Skip to content

Commit e94ce5b

Browse files
fix(html): keep the document after an entity that ends inside a tag
Scope `eofInTag` to the nested tokenize of an entity's replacement text, so later start tags are not dropped; shorten the changeset and note that `xmlconf` passes as a no-op without its submodule. Claude-Session: https://claude.ai/code/session_01WzCD9CDRFzG1j2yQARWzLp Co-authored-by: Alexander Akait <[email protected]>
1 parent 7b3bd25 commit e94ce5b

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎.changeset/020-html-syntax-xml-mode.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": minor
33
---
44

5-
Add an `xml` mode to `html.syntax` that parses and prints XML, DTD entities included.
5+
Add an `xml` mode to `html.syntax` that parses and prints XML.

‎lib/html/syntax-parser.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9320,7 +9320,10 @@ const _dispatchXmlText = (text, start, end) => {
93209320
_xmlEntityRangeEnd = end;
93219321
}
93229322
_xmlEntityStack.push(name);
9323+
// A tag the replacement text ends inside is the entity's to drop, not the document's.
9324+
const outerEofInTag = eofInTag;
93239325
tokenizeXml(replacement, 0, XML_PARSE_CALLBACKS);
9326+
eofInTag = outerEofInTag;
93249327
_xmlEntityStack.pop();
93259328
if (outer === -1) _xmlEntityRangeStart = -1;
93269329
}

‎test/unitCases/HtmlSyntax.unittest.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,6 +3591,16 @@ describe("parseHtml", () => {
35913591
).toBe(source);
35923592
});
35933593

3594+
it("should keep the rest of the document after an entity ending inside a tag", () => {
3595+
const root = /** @type {MatElement} */ (
3596+
parseXml('<!DOCTYPE r [<!ENTITY e "<x">]><r>&e;<y/><z/></r>')
3597+
.children[1]
3598+
);
3599+
expect(
3600+
root.children.map((node) => /** @type {MatElement} */ (node).tagName)
3601+
).toEqual(["y", "z"]);
3602+
});
3603+
35943604
it("should leave a recursive or exponential entity unexpanded", () => {
35953605
const recursive = /** @type {MatElement} */ (
35963606
parseXml(

0 commit comments

Comments
 (0)