Repository navigation
Add missing tags to openImpliesClose for open <p> elements - #2493
Conversation
Per the WHATWG HTML parsing spec, the list of start tags whose start implies the end of an open <p> element includes center, dialog, dir, hgroup, menu, search and summary. These entries were missing from the openImpliesClose map, so htmlparser2 nested these elements inside an open <p> instead of closing it, diverging from browser behavior. Add the seven missing entries and a regression test asserting that an open <p> is closed before <hgroup> opens. All 188 tests pass (vitest run). Co-authored-by: FirmamentalSpring <287222957+FirmaSpring@users.noreply.github.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing: 2
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly describes the main change: adding missing tags to openImpliesClose so they close open elements. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the tags in line,
“Close the paragraph; all is fine.” <hgroup> starts with events in place,
Seven tags now share the case.
Hop, hop—clean parsing wins!
Comment @coderabbitai help to get the list of available commands.
[Medium impact] The PR appears safe to merge; the callback-order test has a non-blocking weakness. Findings
|
lbesecker195
left a comment
There was a problem hiding this comment.
Checked against the WHATWG tree-construction rules for the "in body" insertion mode: the start tags that close a p in button scope include center, dialog, dir, hgroup, menu, search, and summary, all of which were missing from openImpliesClose. Test added. LGTM.
|
thanks! |
| const pClose = onclosetag.mock.calls.findIndex( | ||
| ([name]) => name === "p", | ||
| ); | ||
| const hgroupOpen = onopentag.mock.calls.findIndex( | ||
| ([name]) => name === "hgroup", | ||
| ); | ||
| expect(pClose).toBeLessThan(hgroupOpen); |
There was a problem hiding this comment.
pClose and hgroupOpen are indexes in different spies, so comparing them does not check callback order. This test would still pass if onopentag("hgroup") ran before onclosetag("p", true), provided the paragraph closed first among close callbacks. Compare the spies’ mock.invocationCallOrder values or record both callbacks in one shared list.
Knowledge Base Used: Parser events and document state
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Problem
Per the WHATWG HTML parsing spec (https://html.spec.whatwg.org/multipage/syntax.html#optional-tags), the list of start tags whose start implies the end of an open
<p>element includescenter,dialog,dir,hgroup,menu,searchandsummary. These entries are missing from theopenImpliesClosemap insrc/Parser.ts, so htmlparser2 nests these elements inside an open<p>instead of closing it, diverging from browser behavior. For example, parsing<p>text<menu>item</menu>keeps the<menu>inside the paragraph.Fix
Add the seven missing entries to
openImpliesClose:<p>Verification
src/Parser.spec.tsasserting that an open<p>is implicitly closed before<hgroup>opens.vitest run: 7 test files, 188 tests passed (including the new regression test).Co-authored-by: FirmamentalSpring 287222957+FirmaSpring@users.noreply.github.com
Summary by CodeRabbit
Bug Fixes
Tests
<hgroup>element begins.