Invalid regex due to chrome update

Description

Steps to reproduce

  1. Go to an app's settings page.
  2. Input an invalid domain name in the domain field
  3. 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

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.

Screenshots