Repository navigation
Conversation
htmlparser2 12 reports a CDATA section in foreign content (SVG) as plain text without oncdatastart/oncdataend, so the adapter dropped the markers and <svg><style><![CDATA[...]]></style></svg> lost its wrapper on round trip. Restore the markers when the text token starts at a CDATA section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Regression in 0.13.0 (htmlparser2 12): CDATA sections inside SVG lose their markers in HTML mode.
Cause. htmlparser2 12 tracks foreign content and, in HTML mode, reports a CDATA section inside SVG via
ontext(value)only.oncdatastart/oncdataendfire only inxmlModeor withrecognizeCDATA(seeParser.oncdata). The adapter therefore received just the inner text.Fix. In
ontext, when not inxmlMode/recognizeCDATA, the source atparser.startIndexstarts with<![CDATA[and the text itself does not (raw-text elements like HTML<script>already contain the markers), wrap the text back in<![CDATA[…]]>. Same source-slice approach asoncommentuses for declarations.Behavior by context (0.11 / 0.12 → this PR):
<style>/<script>: markers kept in 0.11/0.12, dropped in 0.13.0, kept again.<text>: 0.11/0.12 turned CDATA into a comment (<!--[CDATA[a<b]]-->, hiding the text), 0.13.0 dropped the markers; now kept as written.<mi>): comment, unchanged (spec behavior).xmlMode/recognizeCDATA: plain text without markers, unchanged (existing test).Tests: SVG style/script, SVG text with surrounding text, no duplicated markers in raw-text
<script>, comment outside foreign content and in<mi>,recognizeCDATA. The three new SVG tests fail without the fix.npm run checkpasses, coverage ofsrc/index.ts100%.Downstream: htmlnano
masterwith this parser and posthtmlmaster(incl. posthtml/posthtml#421): all 6 CDATA/SVG tests that failed with 0.13.0 pass. The remaining 15 failures are<plaintext>rendering (the renderer emits end tags that never existed in the source), to be handled in posthtml-render.Proposed as 0.13.1.
🤖 Generated with Claude Code