Skip to content

fix(html): prevent Handlebars tags from corrupting HTML tag stack - #2502

Merged
bitwiseman merged 5 commits into
beautifier:mainfrom
JessenReinhart:fix/handlebars-tag-stack-2045
Jul 14, 2026
Merged

fix(html): prevent Handlebars tags from corrupting HTML tag stack#2502
bitwiseman merged 5 commits into
beautifier:mainfrom
JessenReinhart:fix/handlebars-tag-stack-2045

Conversation

@JessenReinhart

Copy link
Copy Markdown

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_element was written for HTML optional-end-element logic but ran on all tags including Handlebars tags. When it encountered {{#tr}}, it matched the HTML tr branch 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 === '{'), set parser_token.parent and 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).

Comment thread test/data/html/tests.js
Comment thread test/data/html/tests.js Outdated
Comment thread test/data/html/tests.js
Co-authored-by: Liam Newman <bitwiseman@gmail.com>

@bitwiseman bitwiseman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Very efficient way to address the immediate issue in a low risk way.

@bitwiseman
bitwiseman merged commit 305a0c0 into beautifier:main Jul 14, 2026
12 checks passed
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.

2 participants