Skip to content

Commit 9776ce6

Browse files
josepharharChromium LUCI CQ
authored and
Chromium LUCI CQ
committed
Add InputClosesSelect flag
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}
1 parent 1578918 commit 9776ce6

File tree

7 files changed

+46
-0
lines changed

7 files changed

+46
-0
lines changed

third_party/blink/renderer/core/html/parser/html_tree_builder.cc

+5
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,11 @@ void HTMLTreeBuilder::ProcessStartTagForInBody(AtomicHTMLToken* token) {
748748
ProcessCloseWhenNestedTag<IsLi>(token);
749749
break;
750750
case HTMLTag::kInput: {
751+
if (RuntimeEnabledFeatures::InputClosesSelectEnabled()) {
752+
if (tree_.OpenElements()->InScope(HTMLTag::kSelect)) {
753+
ProcessFakeEndTag(HTMLTag::kSelect);
754+
}
755+
}
751756
// Per spec https://html.spec.whatwg.org/C/#parsing-main-inbody,
752757
// section "A start tag whose tag name is "input""
753758

third_party/blink/renderer/platform/runtime_enabled_features.json5

+8
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,14 @@
24092409
name: "InnerHTMLParserFastpathLogFailure",
24102410
status: "experimental",
24112411
},
2412+
{
2413+
// Makes the HTML parser close <select> tags before inserting <input>
2414+
// tags to match the old parser behavior in case we have compat issues
2415+
// launching SelectParserRelaxation. If SelectParserRelaxation stays
2416+
// stable in M131, then this flag can be removed in M133.
2417+
name: "InputClosesSelect",
2418+
depends_on: ["SelectParserRelaxation"],
2419+
},
24122420
{
24132421
name: "InputMultipleFieldsUI",
24142422
// No plan to support complex UI for date/time INPUT types on Android and

third_party/blink/web_tests/VirtualTestSuites

+10
Original file line numberDiff line numberDiff line change
@@ -3497,6 +3497,16 @@
34973497
"expires": "Feb 1, 2025",
34983498
34993499
},
3500+
{
3501+
"prefix": "input-closes-select",
3502+
"platforms": ["Linux"],
3503+
"bases": [
3504+
"external/wpt/html/semantics/forms/the-select-element/customizable-select/select-parsing.tentative.html"
3505+
],
3506+
"args": ["--enable-features=InputClosesSelect,SelectParserRelaxation"],
3507+
"expires": "Feb 1, 2025",
3508+
3509+
},
35003510
"css-custom-state-deprecated-syntax-enabled is the configuration that is",
35013511
"currently shipping to stable.",
35023512
{

third_party/blink/web_tests/external/wpt/html/semantics/forms/the-select-element/customizable-select/select-parsing.tentative.html

+11
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
</div>
4343
</select>
4444

45+
<select id=s7>
46+
<input>
47+
</select>
48+
4549
<div id=afterlast>
4650
keep this div after the last test case
4751
</div>
@@ -100,6 +104,13 @@
100104
`);
101105
}, 'Divs and imgs should be allowed as direct children of select and within options without a datalist.');
102106

107+
test(() => {
108+
assert_equals(document.getElementById('s7').parentNode, document.body);
109+
assert_equals(document.getElementById('s7').innerHTML, `
110+
<input>
111+
`);
112+
}, 'Input tags should parse inside select instead of closing the select.');
113+
103114
test(() => {
104115
assert_equals(document.getElementById('afterlast').parentNode, document.body);
105116
}, 'The last test should not leave any tags open after parsing.');

third_party/blink/web_tests/virtual/customizable-select-disabled/external/wpt/html/semantics/forms/the-select-element/customizable-select/select-parsing.tentative-expected.txt

+2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ This is a testharness.js-based test.
1111
assert_equals: expected "\\n <button>\\n <div>\\n </div></button>" but got "\\n \\n \\n "
1212
[FAIL] Divs and imgs should be allowed as direct children of select and within options without a datalist.
1313
assert_equals: expected "\\n <div>\\n <option><img>option</option>\\n </div>\\n" but got "\\n \\n <option>option</option>\\n \\n"
14+
[FAIL] Input tags should parse inside select instead of closing the select.
15+
assert_equals: expected "\\n <input>\\n" but got "\\n "
1416
Harness: the test ran to completion.
1517

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This suite enables InputClosesSelect flag, which re-adds legacy behavior to the
2+
HTML parser which turns `<select><input>` into `<select></select><input>` to
3+
de-risk the launch of SelectParserRelaxation.
4+
5+
--enable-features=SelectParserRelaxation,InputClosesSelect
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This is a testharness.js-based test.
2+
[FAIL] Input tags should parse inside select instead of closing the select.
3+
assert_equals: expected "\\n <input>\\n" but got "\\n "
4+
Harness: the test ran to completion.
5+

0 commit comments

Comments
 (0)