Invalid regex due to chrome update
Description
Steps to reproduce
- Go to an app's settings page.
- Input an invalid domain name in the domain field
- Open devtools
Expected behaviour
No errors in devtools, domain input has a validation error
Actual behaviour
No validation error. This message in console: Pattern attribute value ... is not a valid regular expression.
Stack trace
Pattern attribute value ^(([\da-z](?:(?!.*--)[\da-z-]*[\da-z])?)+\.)+[a-z]{2,}$ is not a valid regular expression: Uncaught SyntaxError: Failed to read the 'patternMismatch' property from 'ValidityState': Invalid regular expression: /^(([\da-z](?:(?!.*--)[\da-z-]*[\da-z])?)+\.)+[a-z]{2,}$/v: Invalid character class
(anonymous) @ c32f23cd6b1d6668d7c6.js:2
il @ c32f23cd6b1d6668d7c6.js:2
Sd @ c32f23cd6b1d6668d7c6.js:2
(anonymous) @ c32f23cd6b1d6668d7c6.js:2
S @ c32f23cd6b1d6668d7c6.js:2
M @ c32f23cd6b1d6668d7c6.js:2
Explanation
- https://github.com/GoogleChrome/chromium-dashboard/issues/3106
- https://groups.google.com/a/chromium.org/g/blink-dev/c/gIyvMw0n2qw?pli=1
Chrome assumed this won't break many people's pages. It does break some of our regexes though. Our only choice is to find and update any noncompliant regexes. Those include:
- Unescaped special characters in a character class (e.g.
[)],[(],[a-zA-Z-]needs to be[a-zA-Z\-even though the former is valid anywhere else but in HTML) \d- and so on (SO asnwer)
We cannot escape \d to \\d, as the 0-vote other answer to this question suggests.