Repository navigation
Conversation
…on#341) TextElement.toString() put the element text back at the first "><" of its childless clone, which can be inside an attribute value, so a style, script, title or textarea with such an attribute serialized its text into the attribute and an empty element body. The text now goes right before the end tag, the last "></" of the clone. A clone that self-closes (in an XML document) is returned as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Check for the self-closing form first, so an attribute value with "></" in a text element imported into an XML document cannot take the text. Co-Authored-By: Claude Opus 5.5 (1M context) <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.
Fixes #341.
TextElement.toString()put the element text back at the first><of its childless clone. That can be inside an attribute value, so a<style>,<script>,<title>or<textarea>whose attribute contains><was serialized with its text inside the attribute and an empty body. A parse →toString()round trip loses the stylesheet the same way:In an HTML document the clone serializes as
<tag attrs></tag>, so the text now goes right before the end tag, at the last></. It's a plainlastIndexOfandslice, so$patterns in the text stay literal, as #293 intended.A text element imported into an XML document serializes self-closed (
<style ... />). That clone is now returned unchanged, so its attributes stay intact. On main the text there was dropped, or written into an attribute containing><. That check is the one new branch, under/* c8 ignore next */.style,script,title,textareawithdata-src="a><b.css")worker.js)<textarea placeholder="<a></a>">hiplaceholder="<a>hi</a>", empty bodyhiin the body$&/$`in the text,</script>in an attribute<style />; with><in an attribute, the text goes into that attribute<style />, or<style data-src="a><b" />with its attribute intactcjs/html/text-element.jsandworker.jscarry the same change. A full rebuild ofworker.jsalso pulls in #339'sgetAttributeValuechange, which I left out to keep this to one concern.Validation
npm run build(tsc, cjs, rollup, thennpm test: eslint, benchmark, both test passes, c8) exits 0 on Windows 11 with Node 24.19. On Linux (WSL Ubuntu) with Node 20.20.2, the version CI uses,npm ci,npm run build,npm testandnpm run coverageall exit 0. Coverage stays at 100% statements, branches and lines (functions 99.75%, the same as main).Prepared with AI assistance (Claude Code); verified by the reporter's script from #341 against esm, cjs and
worker.js, an edge-case comparison against main, and thenpmruns above.🤖 Generated with Claude Code