Skip to content

Add tree construction tests for void elements inside phrasing containers#194

Draft
nghamilton wants to merge 1 commit intohtml5lib:masterfrom
nghamilton:void-in-phrasing-tests
Draft

Add tree construction tests for void elements inside phrasing containers#194
nghamilton wants to merge 1 commit intohtml5lib:masterfrom
nghamilton:void-in-phrasing-tests

Conversation

@nghamilton
Copy link

@nghamilton nghamilton commented Mar 16, 2026

Summary

The existing tree construction test suite has no test cases for void elements (<br>, <input>, <img>, <wbr>, <embed>) as children of <p>, heading, or formatting elements.

This is a gap because the "in body" insertion mode handles these void elements via the "reconstruct the active formatting elements, insert an HTML element, pop" path - but a buggy parser could incorrectly route them through closePElement instead, causing <p><br></p> to produce <p></p><br> (closing the paragraph before inserting the break).

The combination <p><br></p> is common in real-world HTML.

Test cases (13)

  • <br> inside <p> (with/without surrounding text, multiple <br>s) - 5 cases
  • <br> inside <h1> - 1 case
  • <input>, <img>, <wbr>, <embed> inside <p> - 4 cases
  • <input> inside <h2> - 1 case
  • <br> inside formatting elements (<em>, <strong>) - 2 cases

All test cases use <!DOCTYPE html> prefix (no parse errors expected).

These tests add coverage for void elements (<br>, <input>, <img>, <wbr>, <embed>) as children of phrasing containers (<p>, headings, formatting elements). The html5lib reference parser already handles these cases correctly - the gap is in test suite coverage. These tests help other implementations catch a class of bug. CI failures are pre-existing and unrelated to this PR (parse5 hasn't implemented recent <select> content model changes).

Relevant spec sections

  • 12.2.6.4.7 "Any other start tag" - the area, br, embed, img, keygen, wbr case reconstructs active formatting elements, inserts, and immediately pops. It must NOT call the "close a p element" algorithm.

Copy link
Contributor

@annevk annevk left a comment

Choose a reason for hiding this comment

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

These look fine to me.

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