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

regexp.escape needs to escape leading digits #3656

Closed
bakkot opened this issue Sep 19, 2023 · 1 comment · Fixed by #6208
Closed

regexp.escape needs to escape leading digits #3656

bakkot opened this issue Sep 19, 2023 · 1 comment · Fixed by #6208
Labels
bug Something isn't working needs help

Comments

@bakkot
Copy link

bakkot commented Sep 19, 2023

The escape function neglects to escape leading digits, which means it doesn't actually work in all contexts:

// ten characters, followed by the first character again, followed by the user input
let getMatch = input => new RegExp(`^(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\1${escape(input)}$`);

// seems to work!
console.log(getMatch('x').test('abcdefghijax')); // true

// unless the user input starts with a 0...
console.log(getMatch('0').test('abcdefghija0')); // false
console.log(getMatch('0').test('abcdefghijj')); // true
@bakkot bakkot added bug Something isn't working needs triage labels Sep 19, 2023
@kt3k kt3k removed the needs triage label Sep 22, 2023
@lionel-rowe
Copy link
Contributor

lionel-rowe commented Sep 23, 2024

@bakkot See also #5794

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs help
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants