-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fix es.regexp.constructor - handleNCG
- consider captured groups inside non-capturing groups
#1352
Conversation
} | ||
result += chr; | ||
groupid++; |
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.
It will break cases like
RegExp('foo:(?<foo>\\w+),bar:(\\w+),buz:(?<buz>\\w+)').exec('foo:abc,bar:def,buz:ghi').groups.buz
since here is a non-named group.
Could you fix it and add a couple of cases like that to the tests?
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.
Yes, you are right. Changes like these really break some cases.
I added an additional check to a non-capturing group after '(' character and revert the previous changes.
Also extended regexp constructor test with your example.
Could you fix linting issues? Note that |
oops, didn't pay attention to the linter |
Thanks. |
handleNCG
method from es.regexp.constructor does not work correctly in some cases.If named captured group placed inside non-capturing group(or other group, that doesn't follow
(?<group_name>...)
pattern) then group id counter extra incremented.Real example: H_REGEX from vscode repository.
const H_REGEX = /(?<tag>[\w\-]+)?(?:#(?<id>[\w\-]+))?(?<class>(?:\.(?:[\w\-]+))*)(?:@(?<name>(?:[\w\_])+))?/;
When it used through RegExp constructor
new RegExp('(?<tag>[\\w\\-]+)?(?:#(?<id>[\\w\\-]+))?(?<class>(?:\\.(?:[\\w\\-]+))*)(?:@(?<name>(?:[\\w\\_])+))?')
, exec method return wrong groups values. Tested on'div.editor.original@original'
input value.With polyfill:
Native:
Link to test