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

Ensure the result works with the u flag #52

Closed
domenic opened this issue Feb 16, 2021 · 1 comment
Closed

Ensure the result works with the u flag #52

domenic opened this issue Feb 16, 2021 · 1 comment

Comments

@domenic
Copy link
Member

domenic commented Feb 16, 2021

I recently enabled the ESLint rule which encourages always using the u flag. When doing so, I found out that my custom regexp escaper, which was

function escapeRegExp(str) {
  return str.replace(/[-[\]/{}()*+?.\\^$|]/ug, "\\$&");
}

was overzealous, and would cause new RegExp(escapeRegExp(input), "ug") to fail when the input string contained a -.

This probably has some intersection with discussions in other threads, e.g. if some delegates require that the result escape - so that it can work in situations like new RegExp("[" + RegExp.escape(input) + "]", "ug"), such a requirement prohibits the result from working in situations like new RegExp(RegExp.escape(input), "ug").

@bakkot
Copy link
Collaborator

bakkot commented Feb 16, 2021

Yeah, as I suggested in that thread, I think if we include - in this proposal we'd need to change u-mode regexes so that \- is treated an identity escape, i.e. it maps to - .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants