Closed RusKnyaz closed 5 years ago
Looks like the issue is that in .NET the $
character matches \n
(in multiline mode):
new Regex("^.*$", RegexOptions.Multiline).Matches("one\r\ntwo\r\n")[0].Value
// returns "one\r"
Whereas in javascript it matches \r
or \n
:
'one\r\ntwo\r\n'.match(/^.*$/m)[0]
// returns "one"
The workaround is to change your regular expression:
var rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg;
Unfortunately I cannot use a workaround because this code is from jquery. And there are probably tons of code on web pages that use regular expressions. Please look at the similar issue in jint
@RusKnyaz For implementation of regular expressions in the Jurassic, Jint and NiL.JS engines are used a System.Text.RegularExpressions.Regex
class, which is not fully compatible with ECMAScript (see the “Regular expression parsing error” issue).
@Taritsyn I kown it. And It is possible to fix. Please look the link I provided in previous comment.
I've checked in a fix, let me know if it works for you :-)
@RusKnyaz You'll notice that my fix is more complicated than the Jint one. It seems the fix in Jint is not correct. 'one\r\ntwo'.match(/^.*$/mg).toString()
should return "one,,two" but in Jint it returns "one\r,two".
@RusKnyaz You'll notice that my fix is more complicated than the Jint one. It seems the fix in Jint is not correct.
'one\r\ntwo'.match(/^.*$/mg).toString()
should return "one,,two" but in Jint it returns "one\r,two".
It seems the fix in Jurassic is also not 100% correct :wink:
E.g. ('one\\\r'.match(/^.*\\$/mg) || []).toString()
should return "one\\"
but returns ""
.
Ha, you're right, darn it.
I checked in a fix for the escaping issue.
Execute the code:
Expected: arr is array of ["x-aspnetmvc-version", "4.0", "x-powered-by", "ASP.NET"] Observed: arr is empty.