Skip to content

fix(extract-tf): read <select> by the 2025 standard's rules, as Chromium does - #152

Closed
77777R7 wants to merge 1 commit into
claude/parse5-foreign-endfrom
claude/parse5-select
Closed

77777R7 wants to merge 1 commit into
claude/parse5-foreign-endfrom
claude/parse5-select

Conversation

@77777R7

@77777R7 77777R7 commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #151 (claude/parse5-foreign-end); it retargets as the stack merges. This fixes the last Known gap from #137, Chromium's newer <select> parsing.

Problem

In July 2025 the HTML Standard dropped the "in select" and "in select in table" insertion modes (whatwg/html#10548, part of customizable <select>). Chromium has parsed <select> that way since version 134; our oracle runs Chromium 151. parse5 8.0.1 still uses the old modes. Inside a select it kept only text, <option>, <optgroup> and <hr>, and it dropped every other tag.

Input Chromium 151 Before
<select><div>a</div><option>b</select> <select><div>a</div><option>b</option></select> <select>a<option>b</option></select>
<select><b>a</select>b <select><b>a</b></select><b>b</b> <select>a</select>b
<p><select><p>x <p><select><p>x</p></select></p> <p><select>x</select></p>
<select><textarea>t</textarea>x <select><textarea>t</textarea>x</select> <select></select><textarea>t</textarea>x
<table><select><input type=hidden>x <select><input type="hidden">x</select><table></table> <select></select>x<table><input type="hidden"></table>

Change

packages/extract-tf/src/dom.ts, StandardParser, following the live standard (parsing.html#parsing-main-inbody):

  • No select modes. An insertionMode accessor on StandardParser.prototype drops parse5's switches to IN_SELECT and IN_SELECT_IN_TABLE. This covers every path, including those that call parse5's in-body handler directly: after head, after body, and the template's top level. The reset of the insertion mode no longer has a select branch.
  • <select> bounds every scope. hasInScope, hasInButtonScope, hasInListItemScope and hasNumberedHeaderInScope are replaced by scoped(), whose HTML bounds include select.
  • Rules while a select is open in scope (inSelect):
    • <select> pops to the open select;
    • <option> and <optgroup> generate implied end tags;
    • <hr> closes a <p>, then generates implied end tags;
    • <input> pops the select. In the table modes, a hidden <input> follows the table's own rule.
    • In the table modes these tags are read as their "anything else", with foster parenting.
  • </select> is read as one of the body's block end tags: it generates implied end tags and pops to the select.
  • Speed. A count of open selects (from onItemPush and onItemPop) lets a page without a select skip the scope walk entirely. scoped() also avoids closures.

EXTRACTOR_VERSION is now extract-tf/18. Markdown skips the select itself, but what follows can change: <p>a <select><b>x</select>b</p> gives a **b**, not a b. Links and images inside options are now collected, as they are in the browser's DOM. The version test's digest is unchanged.

Tests

Chromium oracle (151.0.7922.34)

Random inputs of select, option, optgroup, form controls, table, template and formatting tags:

Seed Pages: before → after Fragments: before → after
1 3,488 → 5,001 of 5,001 3,494 → 5,000 of 5,000
2 3,471 → 5,001 3,479 → 5,000
3 3,514 → 5,001 3,520 → 5,000
9 3,444 → 5,001 3,452 → 5,000
  • There are 0 regressions in every run.
  • Earlier token sets (table and template; svg, math and foreignObject; head tags) are unchanged.
  • On the 120 captured pages, the Markdown (main content and whole page), tables, links and images are identical. 64 of these pages have a <select>, and each gives the same tree as before.

Review

A fresh-context reviewer found nothing blocking. It checked:

  • Regressions: none in about 120 hand-picked cases or in its own random oracles. The oracles covered select through every parse5 path, table modes, foreign content, frameset-ok and fragments.
  • Scope callers: every parse5 caller of the scope functions belongs to the standard's default, button or list-item scope, which all include select now.
  • The accessor: it runs for every parser parse5 constructs, including the fragment parser.

It also raised one non-blocking speed point: the select-in-scope check walked the stack for every <input>, <option> or <hr>. The count of open selects fixes that. At 60,000 nested <span>, <input> takes 95 ms (126 before), <option> 85 ms (132), and <select></select> 111 ms (7.2 s). The reviewer then checked the counter against the actual stack after every push and pop over 120,000 random inputs: it found 0 mismatches and the same trees with or without the gate.

Known gaps

🤖 Generated with Claude Code

…ium does

The HTML Standard dropped the "in select" and "in select in table" modes
in July 2025 (whatwg/html#10548); Chromium has parsed <select> so since
version 134. A select and its options now hold what is written in them
(<div>, <b>, <p>, tables, svg, links, images), where parse5 kept only the
text and <option>, <optgroup> and <hr>.

StandardParser now drops parse5's switches to the select modes (an
insertionMode accessor), counts <select> as a bound of every scope, reads
<select>, <option>, <optgroup>, <hr> and <input> by the new rules while a
select is open in scope, and reads </select> as one of the body's block
end tags. A count of open selects keeps pages without one from walking the
stack for it.

Markdown skips the select itself, but what follows it can change (<p>a
<select><b>x</select>b</p> is "a **b**"), and links and images in options
are now collected. Random pages and fragments of select, form-control,
table, template and formatting tags now match Chromium 151 in every case
(1,480 to 1,530 of 5,000 per run differed before); the 120 captured pages
give the same output. EXTRACTOR_VERSION is now extract-tf/18.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: 77777R7 <lunhoward306@gmail.com>
@77777R7

77777R7 commented Oct 4, 2026

Copy link
Copy Markdown
Owner Author

Landed on main through #167 (merge commit 82c925a), which brought the whole stack #113 → #167 in at once after merging main into its top branch. This PR's commits are all in main.

@77777R7 77777R7 closed this Oct 4, 2026
@77777R7
77777R7 deleted the claude/parse5-select branch October 4, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant