Skip to content

Commit

Permalink
Add InputClosesSelect flag
Browse files Browse the repository at this point in the history
This flag is intended to de-risk the launch of SelectParserRelaxation by
partially reverting the new parser behavior to the old parser behavior
specifically in the case of an <input> tag being parsed inside a
<select>. The old parser would convert <select><input> into
<select></select><input>, and based on my research, this is the case
that is most likely going to break sites in SelectParserRelaxation:
whatwg/html#10310

Bug: 373672164
Change-Id: I33b40d11c2001092aa076a219dd56c5ea86f13f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5936092
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Joey Arhar <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1369676}
  • Loading branch information
josepharhar authored and Chromium LUCI CQ committed Oct 16, 2024
1 parent 1578918 commit 9776ce6
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,11 @@ void HTMLTreeBuilder::ProcessStartTagForInBody(AtomicHTMLToken* token) {
ProcessCloseWhenNestedTag<IsLi>(token);
break;
case HTMLTag::kInput: {
if (RuntimeEnabledFeatures::InputClosesSelectEnabled()) {
if (tree_.OpenElements()->InScope(HTMLTag::kSelect)) {
ProcessFakeEndTag(HTMLTag::kSelect);
}
}
// Per spec https://html.spec.whatwg.org/C/#parsing-main-inbody,
// section "A start tag whose tag name is "input""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2409,6 +2409,14 @@
name: "InnerHTMLParserFastpathLogFailure",
status: "experimental",
},
{
// Makes the HTML parser close <select> tags before inserting <input>
// tags to match the old parser behavior in case we have compat issues
// launching SelectParserRelaxation. If SelectParserRelaxation stays
// stable in M131, then this flag can be removed in M133.
name: "InputClosesSelect",
depends_on: ["SelectParserRelaxation"],
},
{
name: "InputMultipleFieldsUI",
// No plan to support complex UI for date/time INPUT types on Android and
Expand Down
10 changes: 10 additions & 0 deletions third_party/blink/web_tests/VirtualTestSuites
Original file line number Diff line number Diff line change
Expand Up @@ -3497,6 +3497,16 @@
"expires": "Feb 1, 2025",
"owners": ["[email protected]", "[email protected]"]
},
{
"prefix": "input-closes-select",
"platforms": ["Linux"],
"bases": [
"external/wpt/html/semantics/forms/the-select-element/customizable-select/select-parsing.tentative.html"
],
"args": ["--enable-features=InputClosesSelect,SelectParserRelaxation"],
"expires": "Feb 1, 2025",
"owners": ["[email protected]", "[email protected]"]
},
"css-custom-state-deprecated-syntax-enabled is the configuration that is",
"currently shipping to stable.",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
</div>
</select>

<select id=s7>
<input>
</select>

<div id=afterlast>
keep this div after the last test case
</div>
Expand Down Expand Up @@ -100,6 +104,13 @@
`);
}, 'Divs and imgs should be allowed as direct children of select and within options without a datalist.');

test(() => {
assert_equals(document.getElementById('s7').parentNode, document.body);
assert_equals(document.getElementById('s7').innerHTML, `
<input>
`);
}, 'Input tags should parse inside select instead of closing the select.');

test(() => {
assert_equals(document.getElementById('afterlast').parentNode, document.body);
}, 'The last test should not leave any tags open after parsing.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ This is a testharness.js-based test.
assert_equals: expected "\\n <button>\\n <div>\\n </div></button>" but got "\\n \\n \\n "
[FAIL] Divs and imgs should be allowed as direct children of select and within options without a datalist.
assert_equals: expected "\\n <div>\\n <option><img>option</option>\\n </div>\\n" but got "\\n \\n <option>option</option>\\n \\n"
[FAIL] Input tags should parse inside select instead of closing the select.
assert_equals: expected "\\n <input>\\n" but got "\\n "
Harness: the test ran to completion.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This suite enables InputClosesSelect flag, which re-adds legacy behavior to the
HTML parser which turns `<select><input>` into `<select></select><input>` to
de-risk the launch of SelectParserRelaxation.

--enable-features=SelectParserRelaxation,InputClosesSelect
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This is a testharness.js-based test.
[FAIL] Input tags should parse inside select instead of closing the select.
assert_equals: expected "\\n <input>\\n" but got "\\n "
Harness: the test ran to completion.

0 comments on commit 9776ce6

Please sign in to comment.