How to write invalid input for encodeURIComponent()?
I browsed the documentation for encodeURIComponent. It mentions
URIError: Thrown if uriComponent contains a lone surrogate.
How to test this while writing a unit test?
You can try an invalid unicode symbol. Something like this: encodeURIComponent('\uDFFF');
Related
I need to correlate the CSRF_NONCE value from the response body of a gatling script.
PTC.flex.csrf.setNonceData('CSRF_NONCE', 'YSgUCGWgJBu8/Fm7I1k7MQuZR1PImDzVGWxSOxeYVUmIvRPuG2Nwfx/RR3WPnnLZDmx6cSvJYSaGzWyMVx8gPFKXEC2PxWONLER+SkrXT3OFkxvKKnhdcQPsU27bwWQ=');
I tried using the below regex check
.check(regex("""PTC.flex.csrf.setNonceData('CSRF_NONCE', '(\S[a-z]*[0-9]*[A-Z]*)');""").saveAs("CSRF1"))
but always getting the output as
"regex(PTC.flex.csrf.setNonceData('CSRF_NONCE', '(\S[a-z]*[0-9]*[A-Z]*)');).find.exists, found nothing"
Please suggest the correct way to give the expression.
Your regex is wrong.
Try
"""PTC\.flex\.csrf\.setNonceData\('CSRF_NONCE', '([a-z0-9A-Z=/\+]*)'\);"""
You can use https://regexr.com/ or write "your regex".r.findAllMatchIn("your string") in Scala to test your regex.
I'm getting the following error at runtime:
Error: [$parse:lexerr] Lexer Error: Unexpected next character at columns 11-11 [\] in expression [[0-9]{1,4}(\.[0-9]{1,3})?].
My HTML looks like this
<input type="text"
class="form-control"
name="amount"
ng-pattern="{{ctrl.pattern}}"
ng-model="ctrl.amount">
The assignment in my AngularJS controller is as follows:
ctrl.pattern = '[0-9]{1,4}(\\.[0-9]{1,3})?';
From what I understand AngularJS appends the ^ and $ at the beginning and end of regular expressions and that works great. The problem is that the regex literal in the middle of the expression is not being accepted. I want to dot to be accepted as a literal and not as any character so I need a way to escape it yet the lexer does not to like it. Is there a way around this?
This issue is already reported here but they are not going to fix it as according to them its a uncommon usecase.
Do it this way instead:
ctrl.pattern = /^[0-9]{1,4}([.][0-9]{1,3})?$/;
This way the regex will be evaluated as a regex object instead of a string parameter to RegExp in which case we will need to add ^,$
There are uncaught assertion error in Chai with Cucumber-js. If in the DocString there are a hyphen - assertion does not work.
So if I have scenario DocString, like
Then I see message:
'''
somewhat1
somewhat2
somewhat3 - somewhat4
'''
I cannot use assert.equal or assert.include assertions because recieve an assertion error, although both arguments is absolutely identical.
If I use DocString without hyphen, like
Then I see message:
'''
somewhat1
somewhat2
somewhat3
'''
there are no any troubles.
Why I recieve an error when use hyphen?
There are any idea how can I use hyphen right in DocString?
Thanks.
Okay there was be trouble because on site use multiple templates with different types of hyphen.it was necessary to use hyphen-minus instead of a dash.
I try test string using regexp in JavaScript.
Correct string looking like:
<script charset="utf-8">new DGWidgetLoader({"width":640,"height":600,"borderColor":"#a3a3a3","pos":{"lat":46.00650100065259,"lon":11.263732910156252,"zoom":9}
I want test that "width", "height" looks like xxx or xxxx, and "lat", "lon"
looks like x{1,2}.x*, zoom looks like x{1,2}
I try use this regex
/<script charset="utf-8">new DGWidgetLoader(/{"width":[0-9]{3,4},"height":[0-9]{3,4},"borderColor":"#a3a3a3","pos":\{"lat":[0-9]{1,2}.[0-9]+,"lon":[0-9]{1,2}.[0-9]+,"zoom":[0-9][0-9]}//
with String.search(), but got error SyntaxError: Invalid regular expression: /<script charset="utf-8">new DGWidgetLoader(/{"width":[0-9]{3,4},"height":[0-9]{3,4},"borderColor":"#a3a3a3","pos":{"lat":[0-9]{1,2}.[0-9]+,"lon":[0-9]{1,2}.[0-9]+,"zoom":[0-9][0-9]}//: Unterminated group
How can i parse script tag that looking like below?
You should escape (, {, } and . with \:
/<script charset="utf-8">new DGWidgetLoader\(\{"width":[0-9]{3,4},"height":[0-9]{3,4},"borderColor":"#a3a3a3","pos":\{"lat":[0-9]{1,2}\.[0-9]+,"lon":[0-9]{1,2}\.[0-9]+,"zoom":[0-9][0-9]\}/
I think the problem is here:
... DGWidgetLoader(/{ ....
Should be:
... DGWidgetLoader\(\{ ...
And the final slash is unnecessary in this case.
EDIT: Also, escape the final } mark and other special characters. So:
/<script charset="utf-8">new DGWidgetLoader\(\{"width":[0-9]{3,4},"height":[0-9]{3,4},"borderColor":"#a3a3a3","pos":\{"lat":[0-9]{1,2}\.[0-9]+,"lon":[0-9]{1,2}\.[0-9]+,"zoom":[0-9][0-9]\}/
Also there is a small logic issue here: your zoom rule requires exactly two numerals while in practice it can be either one or two. You should consider fixing that.
I have the following javascript code:
if (url.match(/?rows.*?(?=\&)|.*/g)){
urlset= url.replace(/?rows.*?(?=\&)|.*/g,"rows="+document.getElementById('rowcount').value);
}else{
urlset= url+"&rows="+document.getElementById('rowcount').value;
}
I get the error invalid quantifier at the /?rows.*?.... This same regex works when testing it on http://www.pagecolumn.com/tool/regtest.htm using the test string
?srt=acc_pay&showfileCL=yes&shownotaryCL=yes&showclientCL=no&showborrowerCL=yes&shownotaryStatusCL=yes&showclientStatusCL=yes&showbillCL=yes&showfeeCL=yes&showtotalCL=yes&dir=asc&closingDate=12/01/2011&closingDate2=12/31/2011&sort=notaryname&pageno=0&rows=anything&Start=0','bodytable','xyz')
In this string, the above regex is supposed to match:
rows=anything
I actually don't even need the /? to get it to work, but if I don't put that into my javascript, it acts like it's not even regex... I'm terrible with Regex period, so this one has me pretty confused. And that error is the only one I am getting in Firefox's error console.
EDIT
Using that link I posted above, it seems that the leading / tries to match an actual forward slash instead of just marking the code as the beginning of a regex statement. So the ? is in there so that if it doesn't match the / to anything, it continues anyway.
RESOLUTION
Ok, so in the end, I had to change my regex to this:
/rows=.*(?=\&?)/g
This matched the word "rows=" followed by anything until it hit an ampersand or ran out of text.
You need to escape the first ?, since it has special meaning in a regex.
/\?rows.*?(?=\&)|.*/g
// ^---escaped
regtest.htm produces
new RegExp("?rows.?(?=\&)|.", "") returned a SyntaxError: invalid
quantifier
The value you put into the web site shouldn't have the / delimiters on the regex, so put in ?rows.*?(?=\&)|.* and it shows the same problem. Your JavaScript code should look like
re = /rows.*?(?=\&)|.*/g;
or similar (but that is a pointless regex as it matches everything). If you can't fix it, please describe what you want to match and show your JavaScript
You might consider refactoring you code to look something like this:
var url = "sort=notaryname&pageno=0&rows=anything&Start=0"
var rowCount = "foobar";
if (/[\?\&]rows=/.test(url))
{
url = url.replace(/([\?\&]rows=)[^\&]+/g,"$1"+rowCount);
}
console.log(url);
Output
sort=notaryname&pageno=0&rows=foobar&Start=0