Skip to content

Commit e4e436c

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 f0a7912 commit e4e436c

4 files changed

Lines changed: 15 additions & 2 deletions

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.

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ Pitfalls that have produced wrong conclusions here:
541541
yarn test:basic --testPathPatterns="ConfigTestCases" --testNamePattern="<category> <case>"
542542
```
543543

544-
Swap `ConfigTestCases` for `StatsTestCases`, `HotTestCases`, `WatchTestCases`, … (full matrix in [TESTING_DOCS.md](TESTING_DOCS.md)). The `test262`, `html5lib`, `syntax-equivalence`, `css-parsing` and `xmlconf` suites use git submodules — run `git submodule update --init --depth 1 test/external/test262-cases test/external/html5lib-tests test/external/wpt test/external/css-parsing-tests test/external/xml-conformance-suite` first, or they fail confusingly.
544+
Swap `ConfigTestCases` for `StatsTestCases`, `HotTestCases`, `WatchTestCases`, … (full matrix in [TESTING_DOCS.md](TESTING_DOCS.md)). The `test262`, `html5lib`, `syntax-equivalence`, `css-parsing` and `xmlconf` suites use git submodules — run `git submodule update --init --depth 1 test/external/test262-cases test/external/html5lib-tests test/external/wpt test/external/css-parsing-tests test/external/xml-conformance-suite` first, or they fail confusingly — except `xmlconf`, which registers a no-op and passes, so a green run without its submodule says nothing about conformance.
545545

546546
**Writing a `configCases/` case:** a case is a mini project — `index.js` (runs assertions; a thrown error fails the test) plus `webpack.config.js`. The emitted bundle is actually executed, so it must run. Optional per-case files: `errors.js` / `warnings.js` export arrays of matchers for expected build diagnostics (without them, any error/warning fails the case); `test.filter.js` returns `false` to skip the case (e.g. gate by Node version — see [Target the Node baseline](#target-the-node-baseline) when the fixture itself needs newer syntax); `test.config.js` customizes the run (e.g. `findBundle`).
547547

‎lib/html/syntax-parser.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9274,7 +9274,10 @@ const _dispatchXmlText = (text, start, end) => {
92749274
_xmlEntityRangeEnd = end;
92759275
}
92769276
_xmlEntityStack.push(name);
9277+
// A tag the replacement text ends inside is the entity's to drop, not the document's.
9278+
const outerEofInTag = eofInTag;
92779279
tokenizeXml(replacement, 0, XML_PARSE_CALLBACKS);
9280+
eofInTag = outerEofInTag;
92789281
_xmlEntityStack.pop();
92799282
if (outer === -1) _xmlEntityRangeStart = -1;
92809283
}

‎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)