Skip to content
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

Regression in @babel/plugin-transform-named-capturing-groups-regex with unicode regexps #10601

Closed
Jessidhia opened this issue Oct 24, 2019 · 2 comments · Fixed by #10447
Closed
Labels
Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@Jessidhia
Copy link
Member

Jessidhia commented Oct 24, 2019

Bug Report

Current Behavior
Likely a regression from #10430, but the contents of u regexps are getting transformed to being non-u without updating a regexp's flags. The problem becomes a more serious bug when the s flag is also present, as the transformed . no longer matches newlines.

Input Code

const re = /<(?<tag>\d)+>.*?<\/\k<tag>>/su
console.log(re.test('<0>xxx\nyyy</0>')) // should be true

Expected behavior/code
A clear and concise description of what you expected to happen (or code).

Output with @7.4.5 (ignoring helpers, just the regexp):

/<(\d)+>.*?<\/\1>/su

Output with @7.6.3:

/<([0-9])+>(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?<\/\1>/su

Note how the regexp, which didn't even have to be transformed from being a unicode regexp (and didn't remove the u flag after doing it), specifically skips over both \x0A and \x0D, the \n and \r characters, which are supposed to be matched because the regexp has the s flag.

Babel Configuration (.babelrc, package.json, cli command)

{
  "plugins": ["plugin-transform-named-capturing-groups-regex"]
}

Environment

  • Babel version(s): 7.6.4
  • Node/npm version: v12.10.0 / yarn 1.19.1
  • OS: macOS 10.15
  • Monorepo: yes
  • How you are using Babel: babel-jest

Possible Solution
Need some way to tell regexpu to not do the unicode downleveling; or if unicode transformation is "inevitable" the dotAll flag needs to be respected.

@nicolo-ribaudo
Copy link
Member

Need to check if it's fixed by #10447

@JLHwung
Copy link
Contributor

JLHwung commented Oct 24, 2019

Will be fixed in #10447, see #10447 (comment) for current approach.

Need some way to tell regexpu to not do the unicode downleveling

True, I have proposed useDotAllFlag support to regexpu-core: mathiasbynens/regexpu-core#34

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 29, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants