Skip to content

Commit

Permalink
Bug 1817171 [wpt PR 38547] - Add tests for <input pattern> enabling t…
Browse files Browse the repository at this point in the history
…he RegExp `v` flag, a=testonly

Automatic update from web-platform-tests
HTML: tests for <input pattern> using the RegExp v flag

HTML PR: whatwg/html#7908.
--

wpt-commits: 000b1c60057e614908f7450353d72f9dda117d33
wpt-pr: 38547
  • Loading branch information
mathiasbynens authored and moz-wptsync-bot committed May 21, 2023
1 parent 2c6d584 commit a32eb7d
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
{conditions: {pattern: null, value: "abc"}, expected: false, name: "[target] The pattern attribute is not set"},
{conditions: {pattern: "[A-Z]+", value: ""}, expected: false, name: "[target] The value attibute is empty string"},
{conditions: {pattern: "[A-Z]{1}", value: "A"}, expected: false, name: "[target] The value attribute matches the pattern attribute"},
{conditions: {pattern: "[A-Z]+", value: "\u0041\u0042\u0043"}, expected: false, name: "[target] The value(ABC) in unicode attribute matches the pattern attribute"},
{conditions: {pattern: "[A-Z]+", value: "\x41\x42\x43"}, expected: false, name: "[target] The value(ABC) in unicode attribute matches the pattern attribute"},
{conditions: {pattern: "[a-z]{3,}", value: "ABCD"}, expected: true, name: "[target] The value attribute mismatches the pattern attribute"},
{conditions: {pattern: "[A-Z]+", value: "ABC123"}, expected: true, name: "[target] The value attribute mismatches the pattern attribute even when a subset matches"},
{conditions: {pattern: "(abc", value: "de"}, expected: false, name: "[target] Invalid regular expression gets ignored"},
{conditions: {pattern: "[(]", value: "x"}, expected: false, name: "[target] Invalid `v` regular expression gets ignored"},
{conditions: {pattern: "a)(b", value: "de"}, expected: false, name: "[target] The pattern attribute tries to escape a group"},
{conditions: {pattern: "a\\u{10FFFF}", value: "a\u{10FFFF}"}, expected: false, name: "[target] The pattern attribute uses Unicode features"},
{conditions: {pattern: "\\u1234\\cx[5-[]{2}", value: "\u1234\x18[6"}, expected: false, name: "[target] The value attribute matches JavaScript-specific regular expression"},
{conditions: {pattern: "\\u1234\\cx[5-[]{2}", value: "\u1234\x18[4"}, expected: true, name: "[target] The value attribute mismatches JavaScript-specific regular expression"},
{conditions: {pattern: "\\u1234\\cx[5-\\[]{2}", value: "\u1234\x18[6"}, expected: false, name: "[target] The value attribute matches JavaScript-specific regular expression"},
{conditions: {pattern: "\\u1234\\cx[5-\\[]{2}", value: "\u1234\x18[4"}, expected: true, name: "[target] The value attribute mismatches JavaScript-specific regular expression"},
]
},
{
Expand All @@ -34,14 +35,15 @@
{conditions: {multiple: true, pattern: null, value: "abc,abc"}, expected: false, name: "[target] The pattern attribute is not set, if multiple is present"},
{conditions: {multiple: true, pattern: "[A-Z]+", value: ""}, expected: false, name: "[target] The value attibute is empty string, if multiple is present"},
{conditions: {multiple: true, pattern: "[A-Z]{1}", value: "A,A"}, expected: false, name: "[target] The value attribute matches the pattern attribute, if multiple is present"},
{conditions: {multiple: true, pattern: "[A-Z]+", value: "\u0041\u0042\u0043,\u0041\u0042\u0043"}, expected: false, name: "[target] The value(ABC) in unicode attribute matches the pattern attribute, if multiple is present"},
{conditions: {multiple: true, pattern: "[A-Z]+", value: "\x41\x42\x43,\x41\x42\x43"}, expected: false, name: "[target] The value(ABC) in unicode attribute matches the pattern attribute, if multiple is present"},
{conditions: {multiple: true, pattern: "[a-z]{3,}", value: "abcd,ABCD"}, expected: true, name: "[target] The value attribute mismatches the pattern attribute, if multiple is present"},
{conditions: {multiple: true, pattern: "[A-Z]+", value: "ABCD,ABC123"}, expected: true, name: "[target] The value attribute mismatches the pattern attribute even when a subset matches, if multiple is present"},
{conditions: {multiple: true, pattern: "(abc", value: "de,de"}, expected: false, name: "[target] Invalid regular expression gets ignored, if multiple is present"},
{conditions: {multiple: true, pattern: "[(]", value: "x"}, expected: false, name: "[target] Invalid `v` regular expression gets ignored, if multiple is present"},
{conditions: {multiple: true, pattern: "a)(b", value: "de,de"}, expected: false, name: "[target] The pattern attribute tries to escape a group, if multiple is present"},
{conditions: {multiple: true, pattern: "a\\u{10FFFF}", value: "a\u{10FFFF},a\u{10FFFF}"}, expected: false, name: "[target] The pattern attribute uses Unicode features, if multiple is present"},
{conditions: {multiple: true, pattern: "\\u1234\\cx[5-[]{2}", value: "\u1234\x18[6,\u1234\x18[Z"}, expected: false, name: "[target] The value attribute matches JavaScript-specific regular expression, if multiple is present"},
{conditions: {multiple: true, pattern: "\\u1234\\cx[5-[]{2}", value: "\u1234\x18[4,\u1234\x18[6"}, expected: true, name: "[target] The value attribute mismatches JavaScript-specific regular expression, if multiple is present"},
{conditions: {multiple: true, pattern: "\\u1234\\cx[5-\\[]{2}", value: "\u1234\x18[6,\u1234\x18[Z"}, expected: false, name: "[target] The value attribute matches JavaScript-specific regular expression, if multiple is present"},
{conditions: {multiple: true, pattern: "\\u1234\\cx[5-\\[]{2}", value: "\u1234\x18[4,\u1234\x18[6"}, expected: true, name: "[target] The value attribute mismatches JavaScript-specific regular expression, if multiple is present"},
{conditions: {multiple: true, pattern: "a,", value: "a,"}, expected: true, name: "[target] Commas should be stripped from regex input, if multiple is present"},
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,45 @@
<h1><code>pattern</code> attribute</h1>
<div style="display: none">
<input pattern="[a-z]{3}" value="abcd" id="basic">

<input pattern="a.b" value="a&#x1D306;b" id="unicode-code-points">
<input pattern="\p{ASCII_Hex_Digit}+" value="c0ff33" id="unicode-property-escape">
<input pattern="\p{ASCII_Hex_Digit}+" value="c0ff33" id="unicode-property">

<input pattern="\p{RGI_Emoji}+" value="&#x1F618;&#x1F48B;" id="unicode-property-of-strings">
<input pattern="[\p{ASCII_Hex_Digit}--[Ff]]" value="0123456789abcdefABCDEF" id="set-difference">
<input pattern="[_\q{a|bc|def}]" value="q" id="string-literal">

<div class="breaking-changes-from-u-to-v">
<!-- Unescaped special characters in character classes. -->
<input pattern="[(]" value="foo">
<input pattern="[)]" value="foo">
<input pattern="[[]" value="foo">
<input pattern="[{]" value="foo">
<input pattern="[}]" value="foo">
<input pattern="[/]" value="foo">
<input pattern="[-]" value="foo">
<input pattern="[|]" value="foo">
<!-- Double punctuators in character classes. -->
<input pattern="[&&]" value="foo">
<input pattern="[!!]" value="foo">
<input pattern="[##]" value="foo">
<input pattern="[$$]" value="foo">
<input pattern="[%%]" value="foo">
<input pattern="[**]" value="foo">
<input pattern="[++]" value="foo">
<input pattern="[,,]" value="foo">
<input pattern="[..]" value="foo">
<input pattern="[::]" value="foo">
<input pattern="[;;]" value="foo">
<input pattern="[<<]" value="foo">
<input pattern="[==]" value="foo">
<input pattern="[>>]" value="foo">
<input pattern="[??]" value="foo">
<input pattern="[@@]" value="foo">
<input pattern="[``]" value="foo">
<input pattern="[~~]" value="foo">
<input pattern="[_^^]" value="foo">
</div>
</div>
<div id="log"></div>
<script>
Expand All @@ -24,6 +61,7 @@ <h1><code>pattern</code> attribute</h1>

assert_inherits(input, "validity");
assert_false(input.validity.valid);
assert_true(input.validity.patternMismatch);

assert_true(input.matches(":invalid"));
}, "basic <input pattern> support");
Expand All @@ -32,11 +70,48 @@ <h1><code>pattern</code> attribute</h1>
const input = document.querySelector("#unicode-code-points");
assert_true(input.validity.valid);
assert_true(input.matches(":valid"));
assert_false(input.validity.patternMismatch);
}, "<input pattern> is Unicode code point-aware");

test(() => {
const input = document.querySelector("#unicode-property-escape");
const input = document.querySelector("#unicode-property");
assert_true(input.validity.valid);
assert_true(input.matches(":valid"));
assert_false(input.validity.patternMismatch);
}, "<input pattern> supports Unicode property escape syntax");

test(() => {
const input = document.querySelector("#unicode-property-of-strings");
assert_true(input.validity.valid);
assert_true(input.matches(":valid"));
assert_false(input.validity.patternMismatch);
}, "<input pattern> supports Unicode property escape syntax for properties of strings");

test(() => {
const input = document.querySelector("#set-difference");
assert_false(input.validity.valid);
assert_false(input.matches(":valid"));
assert_true(input.validity.patternMismatch);
}, "<input pattern> supports set difference syntax");

test(() => {
const input = document.querySelector("#string-literal");
assert_false(input.validity.valid);
assert_true(input.validity.patternMismatch);
assert_true(input.matches(":invalid"));
}, "<input pattern> supports string literal syntax");

test(() => {
const inputs = document.querySelectorAll(".breaking-changes-from-u-to-v input");
// These examples are all written such that they’re all `:invalid`
// when using `u`, but would become `:valid` when using `v` because
// the pattern would error, in turn resulting in
// `validity.valid === true`.
for (const input of inputs) {
const html = input.outerHTML;
assert_true(input.validity.valid, `${html} should be valid`);
assert_true(input.matches(":valid"), `${html} should match \`:valid\``);
assert_false(input.validity.patternMismatch, `${html} should not trigger a pattern mismatch`);
}
}, "<input pattern> enables the RegExp v flag");
</script>

0 comments on commit a32eb7d

Please sign in to comment.