#832: TAG review of the proposal to use the RegExp `v` flag instead of `u` for the HTML `pattern` attribute
Discussions
2023-04-tokyo
Some pause wrt backwards compat, but after looking into what the v
flag can do, we think the tradeoffs are very worth it.
Very little breakage, in very few cases, and very little harm in these cases, since client-side validation is a hint anyway.
Propose closing, and plan to close in Plenary.
<blockquote>Hi @mathiasbynens,
@ylafon and I looked at this during a breakout today. While we were slightly concerned initially about the backwards compat implications, we do think the benefits v
brings far outweigh these concerns, and we are happy to see this go forwards.
Thank you for flying TAG!
</blockquote>
OpenedApr 5, 2023
こんにちは TAG-さん!
I'm requesting a TAG review of the proposal to use the RegExp
v
flag instead ofu
for the HTMLpattern
attribute.Summary
Using the new RegExp
v
flag instead ofu
would enable the use of set notation, string literal syntax, and Unicode properties of strings withinpattern
attribute values.Explainer
This proposal makes the
pattern
attribute more powerful, enabling the use of set notation, string literal syntax, and Unicode properties of strings.Differences with the previous
u
flag-based behavior:[FEATURE] Previously invalid patterns now become valid, e.g.
For more useful examples of the RegExp
v
flag, see the relevant feature explainer.[BREAKING CHANGE] Some previously valid patterns are now errors, specifically those with a character class including either an unescaped special character
(
)
[
]
{
}
/
-
\
|
or a double punctuator:Throwing patterns result in
inputElement.validity.valid === true
for any input value, so the only compatibility risk is that some value/pattern combinations that would previously result ininputElement.validity.valid === false
now result ininputElement.validity.valid === true
.Other previously valid patterns still behave the same. (Other than the abovementioned features, the
v
flags only differs in behavior from theu
flag w.r.t. case-insensitive matching, but thepattern
attribute uses case-sensitive matching.)Note that the breaking changes mostly apply to somewhat esoteric edge cases that can easily be avoided. In the worst case, this could cause previously invalid input to now be considered valid (since throwing patterns result in
inputElement.validity.valid === true
for any input value, as if thepattern
attribute wasn’t there). In other words, the only Web Compat risk is that a website without server-side validation would suddenly allow submission of values that would previously be prevented by the client-sidepattern
. All currently allowed inputs would still be accepted, just as they did previously.IMHO making the change is worth it given the powerful new functionality it brings, and the relatively small compatibility risk. This is reminiscent of the discussion in https://github.com/whatwg/html/issues/439 (but in a different direction).
For context, here’s a few pointers w.r.t. when we decided to implicitly enable the
u
flag for thepattern
attribute in the first place:Checklist
Further details
pattern
attribute. The work is in the form of a PR to the WHATWG HTML Standard.UseCounter
giving us the upper bound of potential compat issues. None of theUseCounter
hits so far (see analysis starting with comment #11 on the crbug) constitute an issue in practice.We'd prefer the TAG provide feedback as (please delete all but the desired option):
💬 leave review feedback as a comment in this issue and @-notify
mathiasbynens