Rails url constraint - ruby

Im making a url pass in this date format at the very end of the string
2011-11-02T13:59:26.13Z
I can do this
a.sub!(/\..*/,'')
to knock off the .(digit)(digit)Z and work with the time in my controller.
if i put the time in regular format in my url, it works fine. If i put in the specified format above, i get a blank page. If i add the constraint i made (works fine with chopping the end off in the console, I get an routing (no route matches [GET] ...). What should I do to allow to pass in the date format i need (Im using rails 3 if thats important)

The colon is a reseved character and cannot be used within a URL. See RFC 2366 section 2.2
Also, the . (dot) is used to designate a format type in rails, so when this is passed into the router it will try to render a layout for the '13Z' format.
You should encode that time in another format that does not require these characters.
E.g.
20111102135926
Because each field is fixed width it is still easy to parse with a regex.
You could also atime which can be parsed directly in Ruby.

Related

How to use Power Automate "uriQuery()" function on an url that contains special characters

Due to some odd circumstances I have the necessity to use uriQuery() in a Power Automate flow in order to extract the query string from an url.
This works as expected in most circumstances, except when the url contains special characters like accented letters, for example
http://www.example.com/peppers/JalapeƱo/recipe #1.docx
In such cases the call triggers an error and the exception message shows a (partially) encoded version of my url (why?).
The template language function 'uriQuery' expects its parameter to be a well-formed absolute URI. The provided value was '......'
Obviously the url was indeed a well-formed, absolute URI.
Since the error only triggers when the url contains special characters I assumed that I had to encode the value before calling uriQuery(), yet nothing I tried seems to work (for example encodeUriComponent() ). And as expected nothing I could find on the web mentioned a similar issue.
As a last attempt I am asking here - does uriQuery() support this use-case? And if it does... how?

How to get the required value from the existing value when there is no suffix?

I'm trying to use regular expression extractor concept in Jmeter. By using regEx concept I'm able to get the required token id's. And for all I'm using regEx as (.*?). So this is working fine when we have constant prefix and suffix text/values.
But in this case, there is no suffix,
Ex: Key is = #bluerelay.com/a43a816dcdd14873bd5757b3a3709d5c,
ClickHereForImageForm
I want to take the key ID into a variable with using RegEx. I have tried to get it with (.*?) but it didn't work, it returns the full value, not the required part. It'd be excellent if you could give any suggestion.
The source value is:
https://navitus-internal-app.bluerelay.com/#/token/systemadministrator#bluerelay.com/a43a816dcdd14873bd5757b3a3709d5c
The expected result is to extract a43a816dcdd14873bd5757b3a3709d5c from the above URL and put it into a variable.
You can use regex to get last text after / sign
(.*)\/(\w+)
See demo

breakable slashes everywhere but URLs

I generate pdf (latex) from restructured text using python sphinx (1.4.6) .
I use narrow table column headers with texts like "stuff/misc/other". I need the slashes to be breakable, so the table headers don't overflow into the next column.
The LaTeX solution is to use \BreakableSlash or \slash where necessary. I can use python code to replace all slashes:
from sphinx.util.texescape import tex_replacements
# \BreakableSlash needs package hyphenat to be loaded
tex_replacements.append((u'/', ur'\BreakableSlash ') )
# tex_replacements.append((u'/', ur'\slash ') )
But that will break any URL like http://www.example.com/ into something like
http:\unhbox\voidb#x\penalty\#M\hskip\z#skip/\discretionary{-}{}{}\penalty\#M\hskip\z#skip\unhbox\voidb#x\penalty\#M\hskip\z#skip/\discretionary{-}{}{}\penalty\#M\hskip\z#skipwww.example.com
or
http:/\penalty\exhyphenpenalty/\penalty\exhyphenpenaltywww.example.com
I'd like to use a general solution that works in both cases, where the editor of the documentation can still use normal ReST and doesn't have to worry about latex.
Any idea how to get classic slashes in URLs and breakable slashes everywhere else?
You have not really given data and source code and only asked for an idea, so I take the liberty of only sketching a solution in pseudo code:
Split the document into a list of strings at each position of a space using .split()
For each string, check whether it is an URL by comparing its left side to http:// (and maybe also ftp://, https:// or similar tags)
Do replacements, but only in strings which are no URLs
Recombine all strings including the spaces again, using a command such as " ".join(my_list)
One way to do it, might be to write a Transform subclass. And then use add transform in setup(app) to use it in every read.
I could use DefaultSubstitutions from transforms.py as template for my own class.

Using url unescape to build a url within a view in a string

I am building a url in a view within my sinatra app
I required the URI module in my app.
<li>Show</li>
Without URI.unescape I do not see %20 when I hover over the link. I just see this:
http://127.0.0.1:9292/blog/Coffee Title/49459
I am hoping for that space to be a -. But when I click on the link it will return in my browser as:
http://127.0.0.1:9292/blog/Coffee%20Title/49459
I tried using URI.unescape in irb. I am having trouble evaluating the Ruby code within the string. I am not sure what the right format is but think I am getting close.
URI.escape replaces characters in a string with their percent-encoded counterpart, which is why a space character becomes %20 (20 is the ASCII character code for space). It does not replace spaces with dashes.
To replace a character with another character in a string, use String#tr:
title = "Coffee Title"
title_with_dashes = title.tr(" ", "-")
puts title_with_dashes
# => Coffee-Title
However, this is only half of the equation. You've changed the URLs in your links but as a consequence your server probably isn't going to recognize the URL when someone clicks on the link, because the path that exists is Coffee Title, not Coffee-Title. That's a topic for another question, though.

Passing colons in query string in Apex

I have a link in an apex report which takes the user to different page, and it passes some values to the new page. The button is set to a url because there are too many items being passed, but I don't think that would matter anyway:
f?p=&APP_ID.:27:&SESSION.::&DEBUG.::P27_1,P27_2,P27_3,P27_4,P27_5:0,#1#,#2#,#3#,#NULL#
The #1#, etc. are columns being passed. Everything seems to work correctly except that the data being passed often contains a colon (:), which messes up Apex's built in colon structure by cutting off anything in the new page's item that happens after the colon (including the colon itself) as well as messing up any fields after that. For example: #2# has a colon in it, so P27_3, 4, and 5 will not be filled with values.
I've tried manually replacing the colon with a '%3a' (the url encoding for colon), but it doesn't seem to work.
Try using UTL_URL.ESCAPE() to escape URL special characters and UTL_URL.UNESCAPE() to un-escape them back.
You can also try APEX_UTIL.URL_ENCODE() but you need to use one or the other, i.e. either UTL or APEX_UTIL.

Resources