-
-
Notifications
You must be signed in to change notification settings - Fork 215
Fix ECMA 262 \Z and \z tests #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
}, | ||
"tests": [ | ||
{ | ||
"description": "\\Z should match literal Z", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that \Z should match literal Z
is always correct, so I would argue that it's not justified here.
\Z
(and other unsupported flags) behavior differs in ECMA 262 RegExp depending on the mode.
It's not a valid regexp with u
flag:
> /Z/.test('Z')
true
> /\Z/.test('Z')
true
> /Z/u.test('Z')
true
> /\Z/u.test('Z')
Thrown:
SyntaxError: Invalid regular expression: /\Z/: Invalid escape
Moreover, other tests here imply that pattern matching should be run in unicode mode, which is incompatible with this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you suggest the change, then? I was going by regex101.com.
I don't think that any tests for Moreover, other tests in this repo imply Unicode mode which directly conflicts with this change:
Refs:
|
That said, a js-based impl can trivially pass both the modified test here and the unicode regex test by trying to use Unicode mode, and if that throws on RegExp construction, using the non-Unicode mode. And, arguably, that impl should also pass these tests, unless the mode is explicitly clarified in the JSON Schema spec. Hence I don't think that there should be any tests for Also note that those tests won't be independent though, i.e. if > /Z🐲*/u.test('Z')
true
> /\Z🐲*/u.test('Z')
Thrown:
SyntaxError: Invalid regular expression: /\Z🐲*/: Invalid escape
> /\Z🐲*/.test('Z')
false |
@ChALkeR I agree with everything you're saying, but you know more about JS than I do :) |
I put back the original test. @ChALkeR feel free to suggest what you think this should look like; I'm happy to change to be what you think is more correct. |
I don't think any of these Javascript-specific regex tests are very useful, especially if, as @ChALkeR points out, different modes may need to be used, which makes this very implementation dependent. But... I could be wrong because I'm no Javascript expert. I was just playing around with them on some regex sites and thought the tests could be improved. Maybe not? |
The old test was incorrect because "\Z" is actually valid. It matches a literal Z in ECMA 262.
If this is ambiguity that needs resolving in the spec, yes, let's axe the relevant tests entirely, get the spec clarified, and then add them to the future draft, similar to #309. Sound reasonable? |
Wondering if the "\S" tests are in the same boat? |
Seems likely if they too differ under those two different sections. |
I'm inclined to just remove the "\Z" test instead. See #428 |
lgtmed that PR since it sounds like we'd all agree with that one. Obviously folks speak up if that's not the case but it sounds like all these need confirming/clarifying in the spec and then we follow what the decision is. |
Closing for now in favour of #428 |
I went through the blame history and it turns out this “\Z” test was copied down the chain since Draft-04, and the thinking around regex parsing may have been different. |
@ssilverman Sorry for the delay. Yes, just removing those Re: What differs between the modes is now unknown escapes are treated, e.g.
|
The old test was incorrect because "\Z" is actually valid. It matches a
literal Z in ECMA 262.