Repository navigation
Fix selector matching being skipped for consecutive integration-point siblings - #329
Merged
orium merged 1 commit intoJul 29, 2026
Merged
Conversation
… siblings
The tag scanner emits a hint for most start tags, and the dispatcher sets
got_flags_from_hint so that the lexer's handle_tag does not re-run selector
matching for the same tag. Integration-point start tags (title/desc/
foreignObject in SVG, mi/mo/mn/ms/mtext/annotation-xml in MathML) skip the
hint: the tree-builder simulator answers RequestLexeme and the scanner
switches to the lexer directly.
When a hint kept the parser in scan mode (nothing to capture), the flag was
left set. The next RequestLexeme tag then reached handle_tag with the stale
flag, so selector matching was skipped for it entirely: the element was
emitted verbatim but none of its handlers ran, including the universal
selector. In practice the second of two adjacent integration-point siblings
was invisible to handlers:
<svg><title>x</title><foreignObject>...</foreignObject></svg>
a handler for foreignobject (or *) never fired, while the same element
without the preceding title sibling matched fine.
Clear the flag whenever the hint does not result in a switch to the lexer;
it is only meaningful when the lexer is about to emit the same tag.
robobun
requested review from
a team,
Noah-Kennedy,
jasnell and
orium
as code owners
July 25, 2026 13:35
robobun
added a commit
to oven-sh/bun
that referenced
this pull request
Jul 25, 2026
Bumps the vendored pin from 77127cd2 (v2.7.2) to 02f139c4 (the v3.0.0 tag) and rebases the integration-point patch, which is unchanged upstream and submitted as cloudflare/lol-html#329. v3.0.0 made Settings, MemorySettings and RewriteStrSettings consuming builders with private fields, so the struct-literal construction in html_rewriter.rs and HTMLScanner.rs moves to Settings::new() with with_* setters and append_*_content_handler loops. No behavior change; the OutputSink trait gained set_encoding with a default impl, so our sinks are unaffected. Lockfile: lol_html now wants hashbrown 0.17 and selectors 0.37, both already compatible with the rest of the workspace.
Jarred-Sumner
suggested changes
Jul 25, 2026
Jarred-Sumner
left a comment
There was a problem hiding this comment.
@robobun add a test and make sure you match the style of other commits and any lints in this repo
robobun
added a commit
to oven-sh/bun
that referenced
this pull request
Jul 27, 2026
The patch is waiting on cloudflare/lol-html#329; the registry entry trips on the next lol_html bump past 3.0.0 so the patch cannot outlive the upstream fix silently. Also trims the test comment to the upstream link.
orium
approved these changes
Jul 29, 2026
robobun
added a commit
to oven-sh/bun
that referenced
this pull request
Aug 12, 2026
Upstream merged the integration-point fix (cloudflare/lol-html#329) and released v3.0.1, so the patch, its workarounds-registry entry, and the patches list on the dep go away. v3.0.1 also carries two upstream fixes: linear-depth descendant matching for stray end tags and ASCII case-insensitive attribute-name matching.
robobun
added a commit
to oven-sh/bun
that referenced
this pull request
Aug 16, 2026
Main moved the lolhtml pin to oven-sh/lol-html (bun branch, based on upstream v2.7.2) for content-handler suspension, which reintroduced the integration-point selector-skip bug: upstream fixed it in v3.0.1 (cloudflare/lol-html#329), but the fork predates that. Carry the fix as a vendored patch on the fork pin, registered in the workarounds registry so the next fork rebase past v3.0.0 drops it. The v3.0.1 pin and settings-builder migration from earlier revisions of this branch are gone: the fork keeps the v2.7.2 API, so html_rewriter.rs and HTMLScanner.rs stay as they are on main.
robobun
added a commit
to oven-sh/bun
that referenced
this pull request
Aug 16, 2026
Main moved the lolhtml pin to oven-sh/lol-html (bun branch, based on upstream v2.7.2) for content-handler suspension, which reintroduced the integration-point selector-skip bug: upstream fixed it in v3.0.1 (cloudflare/lol-html#329), but the fork predates that. Carry the fix as a vendored patch on the fork pin, registered in the workarounds registry so the next fork rebase past v3.0.0 drops it. The v3.0.1 pin and settings-builder migration from earlier revisions of this branch are gone: the fork keeps the v2.7.2 API, so html_rewriter.rs and HTMLScanner.rs stay as they are on main.
robobun
added a commit
to oven-sh/bun
that referenced
this pull request
Nov 15, 2026
Main moved the lolhtml pin to oven-sh/lol-html (bun branch, based on upstream v2.7.2) for content-handler suspension, which reintroduced the integration-point selector-skip bug: upstream fixed it in v3.0.1 (cloudflare/lol-html#329), but the fork predates that. Carry the fix as a vendored patch on the fork pin, registered in the workarounds registry so the next fork rebase past v3.0.0 drops it. The v3.0.1 pin and settings-builder migration from earlier revisions of this branch are gone: the fork keeps the v2.7.2 API, so html_rewriter.rs and HTMLScanner.rs stay as they are on main.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
When two SVG/MathML integration-point elements are adjacent siblings, the second one never reaches selector matching. It is emitted to the output verbatim, but no element handler runs for it, including the universal selector:
Remove the
<title>sibling and the sameforeignObjectmatches fine. Intervening text does not re-arm matching; only an intervening non-integration-point element does. This makes selector-based sanitizers built on lol-html bypassable by prefixing the payload element with another integration-point sibling.The cause
The tag scanner emits a tag hint for most start tags;
Dispatcher::apply_capture_flags_from_hint_and_get_next_parser_directivesetsgot_flags_from_hintso the lexer'shandle_tagdoes not re-run selector matching for a tag the hint already matched. Integration-point start tags take a different path: the tree-builder simulator answersRequestLexeme(it needsself_closingto decide namespace entry) and the scanner switches to the lexer without emitting a hint.If the previous tag's hint left the parser in scan mode (nothing to capture),
got_flags_from_hintstayedtrue. The nextRequestLexemetag then reachedhandle_tagwith the stale flag, soadjust_capture_flags_for_tag_lexemewas skipped andhandle_start_tagnever ran for it.The fix
The flag is only meaningful when the hint results in an immediate switch to the lexer for the same tag, so set it to
matches!(directive, ParserDirective::Lex)instead of unconditionallytrue.Two regression tests added next to the existing foreign-content tests in
rewritable_units/element.rs(SVGdesc/title/foreignObjectand MathMLmi/mo/mn/annotation-xmlsibling chains); both fail on main and pass with the fix.cargo testandcargo test --features=_integration_testare green.Found while debugging Bun's HTMLRewriter (oven-sh/bun#35673, ships this change as a vendored patch).