RESOLVED FIXED 288223
RegExp with /v incorrectly handles literal hyphen as creating an invalid range
https://bugs.webkit.org/show_bug.cgi?id=288223
Summary RegExp with /v incorrectly handles literal hyphen as creating an invalid range
Steven Levithan
Reported 2025-02-21 12:41:13 PST
WebKit is throwing a SyntaxError for regexes when all of the following conditions are met: - The regex uses flag `v`. - The regex contains a character class with the following: - Any character set (ex: `\d` or `\p{L}`). - Immediately followed by any representation of a literal hyphen, such as `\-`, `\x2D`, or `\u002D`. - Followed by another token. When this occurs, WebKit treats the literal hyphen as if it was creating a range. So e.g. the perfectly valid regex `/[\d\-a]/v` is handled as if it were the invalid `/[\d-a]/v` and throws "SyntaxError: Invalid regular expression: invalid range in character class for Unicode pattern".
Attachments
Steven Levithan
Comment 1 2025-02-21 12:45:01 PST
Example of this bug in the wild: https://github.com/shikijs/shiki/issues/927
Radar WebKit Bug Importer
Comment 2 2025-02-28 12:42:14 PST
Sosuke Suzuki
Comment 3 2025-03-01 21:30:50 PST
EWS
Comment 4 2025-03-06 10:27:28 PST
Committed 291709@main (7adb2e46f423): <https://commits.webkit.org/291709@main> Reviewed commits have been landed. Closing PR #41732 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.