-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Bug: Named backreferences will always cause a syntax error for non-Unicode regexes in strict parsing mode #23
Comments
Hi. Thank you for your detailed report! Hmm. I'm not 100% sure if it's a spec violation. The two passes parsing came from 22.2.3.2.3 Static Semantics: ParsePattern ( patternText, u ). It says, "if no Please tell me if I went wrong. |
So maybe, this is a spec bug, and IdentityEscape production needs |
I agree with you. I also read the specification like this. This is quite interesting because whether this is a bug or not comes down to the semantic of the As a question to the creator of the library: What is the semantic of the I hope that it's the latter version because that would be a lot more useful IMO. |
I opened an issue: tc39/ecma262#2434 I don't think it's intentional that named capturing groups requires
It disables Annex B completely. |
For people watching this issue: we've already started with our own fork in order to not hold the wider community back anymore: https://github.com/eslint-community/regexpp @mysticatea We would still love to move the original repo to the new @eslint-community though. This PR is released in |
When parsing a non-Unicode regex that contains named backreferences with the
strict: true
option, a syntax error will always be throws regardless of whether the regex is actually correct or not.Example:
This produces the following error:
However, the regex
/(?<foo>A)\k<foo>/
is valid. As stated in the proposal:Since the regex contains a named capturing group,
\k<foo>
has to be parsed as a backreference. Since Annex B doesn't say anything about named backreferences, regexpp should parse this regex even withstrict: true
.However, regexpp parses it as an invalid(?) escape and throws an error in strict mode. This is because validation is done is two passes (1, 2). The bug occurs because the
n
flag isn't set in the first pass causing the syntax error. This can be seen in the stack trace: the second-last line -at RegExpValidator.validatePattern ([...]\validator.ts:531:14)
- is the first parsing pass.The fix for this bug is to determine whether the regex contains named groups ahead of time, similar to how the number of capturing groups is counted before parsing. I will make a PR.
The text was updated successfully, but these errors were encountered: