Skip to content

Commit

Permalink
Use v RegExp flag instead of u for <input pattern>
Browse files Browse the repository at this point in the history
This makes the pattern attribute more powerful, enabling the use of RegExp set notation syntax and properties of strings in its values.

Differences with the previous u flag-based behavior:

- [FEATURE] Previously invalid patterns now become valid, e.g.:

    pattern="[\p{ASCII_Hex_Digit}--[Ff]]"
    pattern="\p{RGI_Emoji}"
    pattern="[_\q{a|bc|def}]"

- [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.

- [STATUS QUO] Other previously valid patterns still behave the same. (Other than the above-mentioned features, the v flags only differs in behavior from the u flag w.r.t. case-insensitive matching, but the pattern attribute uses case-sensitive matching.)

Tests: web-platform-tests/wpt#38547.

Fixes #7908.
  • Loading branch information
mathiasbynens authored Apr 25, 2023
1 parent 5e4c22e commit 4868df6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3032,6 +3032,9 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<ul class="brief">
<li>The <dfn data-x-href="https://tc39.es/proposal-resizablearraybuffer/#sec-isarraybufferviewoutofbounds">IsArrayBufferViewOutOfBounds</dfn> abstract operation</li>
</ul>

<p>User agents that support JavaScript must also implement the <cite>RegExp <code data-x="">v</code> flag</cite>
proposal. <ref spec=JSREGEXPVFLAG></p>
</dd>

<dt>WebAssembly</dt>
Expand Down Expand Up @@ -50855,7 +50858,8 @@ ldh-str = &lt; as defined in <a href="https://www.rfc-editor.org/rfc/rfc10
data-x="concept-fe-values">values</span>, are to be checked.</p>

<p>If specified, the attribute's value must match the JavaScript <i
data-x="js-prod-Pattern">Pattern</i><sub><code data-x="">[+UnicodeMode, +N]</code></sub> production.</p>
data-x="js-prod-Pattern">Pattern</i><sub><code data-x="">[+UnicodeSetsMode, +N]</code></sub> production. <ref
spec=JSREGEXPVFLAG></p>

<div w-nodev>

Expand All @@ -50871,7 +50875,7 @@ ldh-str = &lt; as defined in <a href="https://www.rfc-editor.org/rfc/rfc10
data-x="attr-input-pattern">pattern</code> attribute of the element.</p></li>

<li><p>Let <var>regexpCompletion</var> be <span>RegExpCreate</span>(<var>pattern</var>,
"<code data-x="">u</code>"). <ref spec=JAVASCRIPT></p></li>
"<code data-x="">v</code>"). <ref spec=JSREGEXPVFLAG></p></li>

<li>
<p>If <var>regexpCompletion</var> is an <span data-x="Completion Record">abrupt
Expand All @@ -50886,7 +50890,7 @@ ldh-str = &lt; as defined in <a href="https://www.rfc-editor.org/rfc/rfc10
<var>pattern</var>, followed by "<code data-x="">)$</code>".</p></li>

<li><p>Return ! <span>RegExpCreate</span>(<var>anchoredPattern</var>, "<code
data-x="">u</code>").</p></li>
data-x="">v</code>").</p></li>
</ol>

<p class="note">The reasoning behind these steps, instead of just using the value of the <code
Expand Down Expand Up @@ -133426,6 +133430,9 @@ INSERT INTERFACES HERE
<dt id="refsJSJSONMODULES">[JSJSONMODULES]</dt>
<dd><cite><a href="https://tc39.es/proposal-json-modules/">JSON Modules</a></cite>. Ecma International.</dd>

<dt id="refsJSREGEXPVFLAG">[JSREGEXPVFLAG]</dt>
<dd><cite><a href="https://github.com/tc39/proposal-regexp-v-flag">RegExp <code data-x="">v</code> flag with set notation + properties of strings</a></cite>. Ecma International.</dd>

<dt id="refsJSRESIZABLEBUFFERS">[JSRESIZABLEBUFFERS]</dt>
<dd><cite><a href="https://tc39.es/proposal-resizablearraybuffer/">Resizable ArrayBuffer and growable SharedArrayBuffer</a></cite>. Ecma International.</dd>

Expand Down

0 comments on commit 4868df6

Please sign in to comment.