Repository navigation
Conversation
…ext at the end of the start tag (WebReflection#340, WebReflection#341) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
this feels like potentially a breaking change (behavior changed) but for HTML |
|
Thanks for looking. Yes, there is a concrete break: the value read back after a serialize/parse cycle differs from the value held in the DOM (the full repro is in #340). import { parseHTML } from 'linkedom';
const { document } = parseHTML('<!doctype html><html><body><div id="t"></div></body></html>');
const el = document.getElementById('t');
el.setAttribute('data-x', 'A & B'); // the literal 9 characters A & B
el.outerHTML;
// linkedom today: <div id="t" data-x="A & B"></div>
// browsers: <div id="t" data-x="A &amp; B"></div>
parseHTML(`<!doctype html><html><body>${el.outerHTML}</body></html>`)
.document.getElementById('t').getAttribute('data-x');
// linkedom today: "A & B" (one level of character references lost per cycle)
So |
|
what I mean is that |
…eference (WebReflection#340) Escaping every & changed the output of common markup such as href="?a=1&b=2". An & is now escaped only when the value would be decoded on reparse (checked with the entities attribute decoder htmlparser2 uses), so plain query strings serialize as before and values like "A & B" still round-trip. U+00A0 is left raw: it already round-trips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fair point, that output change was not needed. Pushed 813e5c8: the HTML branch now leaves './page?a=1&b=2' // -> href="./page?a=1&b=2" unchanged
'text3&more' // -> content-desc="text3&more" unchanged
'A & B' // -> data-x="A &amp; B" round-tripsThe Session: a1d4bae0-75ed-48d5-8e05-c2e7d38c46f3 |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #340
Fixes #341
Attr.toString()(#340)In HTML documents
ignoreCase(this)is true, soescape(value)is skipped and only"is replaced. A value that contains a character reference, such as the literalA & B, is written back raw and loses one level of references on every serialize + parse cycle.The HTML branch now keeps a raw
&(sohref="?a=1&b=2"andcontent-desc="text3&more"serialize exactly as before) and escapes&as&only when the value would otherwise be decoded on reparse. The check usesdecodeHTMLAttributefromentities, the decoder htmlparser2 already uses;entities@^7is added as a direct dependency and dedupes with htmlparser2's copy. The XML branch is unchanged.TextElement.toString()(#341)The text was spliced in at the first
><of the childless clone, which can be inside an attribute value. The boundary between start and end tag is always the last><, so the text is now inserted there. The function-style replacement from #293 is kept in effect (no special replacement patterns are interpreted).Tests
test/interface/attr.js(raw&kept, character references escaped and round-tripped) andtest/html/style-element.js.anchor-element.js,meta-element.jsandelement.jspass as onmain.npm testpasses with 100% coverage on the touched files.cjs/andworker.jswere regenerated withnpm run cjsand rollup.🤖 Generated with Claude Code