fix(html): prevent Handlebars tags from corrupting HTML tag stack - #2502
Merged
bitwiseman merged 5 commits intoJul 14, 2026
Merged
Conversation
bitwiseman
reviewed
Jul 3, 2026
bitwiseman
reviewed
Jul 3, 2026
bitwiseman
reviewed
Jul 13, 2026
Co-authored-by: Liam Newman <bitwiseman@gmail.com>
bitwiseman
approved these changes
Jul 13, 2026
bitwiseman
left a comment
Member
There was a problem hiding this comment.
Nice! Very efficient way to address the immediate issue in a low risk way.
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.
Issue #2045
Handlebars helpers with names matching HTML tags (e.g.
{{#tr}}) were incorrectly treated as HTML elements by_do_optional_end_element, which then trashed indentation on the next real HTML tag of the same name.Root cause
_do_optional_end_elementwas written for HTML optional-end-element logic but ran on all tags including Handlebars tags. When it encountered{{#tr}}, it matched the HTMLtrbranch and popped the real<tr>frame off the stack, causing subsequent content inside<td>to be mis-indented.Fix
Added a 6-line guard at the top of
_do_optional_end_element: if the token is a Handlebars tag (tag_start_char === '{'), setparser_token.parentand return immediately — Handlebars tags don't participate in HTML optional-end-element logic.Changes
js/src/html/beautifier.js: skip Handlebars tag tokens in_do_optional_end_element.test/data/html/tests.js: regression test for{{#tr}}inside a<table>.Verification
New regression test passes. All 11,960 HTML beautifier tests pass (no regressions).