Dealing with escaped characters in url - sinatra

I'm trying to map the following url:
/languages/C%23/most_watched_overall.xml
to this action:
get "/languages/:language/:context.xml" do
...
end
The problem is that Sinatra doesn't recognize my mapping and I'm not sure where the problem is.

How about trying it with splats or regex routes? For example:
get "/languages/*/:context.xml" do
params[:splat]
end
See:
http://www.sinatrarb.com/intro#Routes

Related

Multiples document s types refinementfilters

i am using rest api search to get documents with certain extensions types.
I am having this code:
&refinementfilters=or'(fileExtension:equals("aspx"),fileExtension:equals("wmv"))'
The whole code is:
https://myUrl/_api/search/query?selectproperties='Path,Url,Title,Size,IsDocument,PictureUrl,LastModifiedTime'&querytext='wildlife'&refinementfilters= '(fileExtension:equals("aspx"))'
i would like to use rest api refinementfilters fileExtension using or, but the syntax with the OR condition doesn' t work, can you halp me point out
where the problem can be ?
Cheers
To apply multiple filters via refinementfilters property, replace
refinementfilters='(fileExtension:equals("aspx"))'
with
refinementfilters='fileExtension:or("aspx","wmv")'
Example
/_api/search/query?selectproperties='Path,Url,Title,Size,IsDocument,PictureUrl,LastModifiedTime'&querytext='*'&refinementfilters= 'fileExtension:or("docx","pdf")'
As far as general syntax, the quotes for the OR are in the wrong place:
Original version:
&refinementfilters=or'(fileExtension:equals("aspx"),fileExtension:equals("wmv"))'
Corrected version:
&refinementfilters='or(fileExtension:equals("aspx"),fileExtension:equals("wmv"))'

Gatling. Check, if a HTML result contains some string

Programming Gatling performance test I need to check, if the HTML returned from server contains a predefined string. It it does, break the test with an error.
I did not find out how to do it. It must be something like this:
val scn = scenario("CheckAccess")
.exec(http("request_0")
.get("/")
.headers(headers_0)
.check(css("h1").contains("Access denied")).breakOnFailure()
)
I called the wished features "contains" and "breakOnFailure". Does Gatling something similar?
Better solutions:
with one single CSS selector:
.check(css("h1:contains('Access denied')").notExists)
with substring:
.check(substring("Access denied").notExists)
Note: if what you're looking for only occurs at one place in your response payload, substring is sure more efficient, as it doesn't have to parse it into a DOM.
Here ist the solution
.check(css("h1").transform((s: String) => s.indexOf("Access denied"))
.greaterThan(-1)).exitHereIfFailed
You can write it very simple like:
.check(css("h1", "Access denied").notExists)
If you are not sure about H1 you can use:
.check(substring("Access denied").notExists)
IMO server should respond with proper status, thus:
.check(status.not(403))
Enjoy and see http://gatling.io/docs/2.1.7/http/http_check.html for details
EDIT:
My usage of CSS selector is wrong see Stephane Landelle solution with CSS.
I'm using substring way most of the time :)

Pass % encoded in url using perl

I am trying to build a url using CGI input fields. One of the fields contain % as default value. Hence the url is being built as below:
$syscmd = "http://myserver:myport/reports/rwservlet?server=rptsvr+report=$REPORT";
$syscmd .= "+Xprocess=\"$in{'Xprocess'}\"";
The Xprocess variable contains % as default value and the url tunrs out to be something like below:
://myserver:myport/reports/rwservlet?server=rptsvr+report=apu_downtime_p+Xprocess=%
Now I am trying to traverse to that webpage and as % is not encoded to %25, I am facing with an error as shown below
REP-52006: The specified URL %22%%22 cannot be decoded.
Please help on how to encode % character in building the url.
Thank you.
You should use %25 for escaping %.
Here,
http://meyerweb.com/eric/tools/dencoder/
This can be useful in this case.
In your perl code, you could use URI::Encode (http://search.cpan.org/~mithun/URI-Encode-0.09/lib/URI/Encode.pm)

Gatling Transforming Variables

Following some good feedback on previous issue:
Gatling-tool Extracting cookie data
I have a post request in my gatling simulation which looks like the following:
.post("/checkout/onepage/form_key/${formkey}")
The variable ${formkey} is populated from a cookie value using:
.check(headerRegex("Set-Cookie","CACHED_FRONT_FORM_KEY=(.*)").saveAs("formkey"))
This appears to work correctly, however I now have an issue with:
java.net.URISyntaxException: Illegal character in path at index 90
Obviously I need to escape the special characters in the variable, but I'm unsure of how best to do this.
Gatling does provide a transform function:
https://github.com/excilys/gatling/wiki/Checks#wiki-transforming
I'm hoping I can use this to escape the characters. Any ideas would be greatly appreciated.
Yes, query paremeter parts must be URLEncoded.
In Gatling 1, transform takes a String and returns a String, so you would have something like:
.transform(rawCookieValue => java.net.URLEncoder.encode(rawCookieValue, "UTF-8"))

Intuit.Ipp.Data.Qbo.CustomerQuery query with & in the name

How do you use Intuit.Ipp.Data.Qbo.CustomerQuery to query a name like:
Tom & Jerry's
This case has 2 special characters that are causing the query to fail. One being & and the other being '. I've tried to use Uri.EscapeDataString and it doesn't work. Any advice?
The SDK does not encode the ampersand correctly, so you will need to use DevDefined and deserialize the response with the SDK. Code sample: https://gist.github.com/IntuitDeveloperRelations/6024616
you would need to xml encode the string.
thanks
Jarred