Skip to content

Commit 005ec95

Browse files
fix(html): write U+00A0 in a minified attribute as the character (#22208)
`escapeAttribute` escaped U+00A0 as ` ` on both of its paths, but the minifier reaches it only when it re-serializes a value — a value it echoes keeps whatever the source wrote. So one attribute had two printings: a source writing the character kept it, and one writing ` ` kept that. The printer already decodes every other reference in an attribute (`é` prints as `é`) and already keeps U+00A0 literal in a text node, which `_escapeTextContent` documents as the rule. This applies the same rule to the attribute path, keyed on the `minimal` flag that already separates the two callers, so generated markup stays ASCII-safe. The invariant sweeps now gate CI (`yarn test:invariants`, the `invariants` job) rather than being read by hand: both printers are at zero findings, a relation is cheap to hold, and a regression in one is a defect. Two of the seven divergences the sweep carried were its own: a respelling wrote `=""` onto a `{% endif %}`, which restates no value, so a tag another language writes into is now skipped whole. The one that remains is the printer keeping a source spelling shorter than its own, with the reason corrected.
1 parent 102ad33 commit 005ec95

7 files changed

Lines changed: 89 additions & 38 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Write U+00A0 in a minified HTML attribute as the character, not ` `.

‎.github/workflows/test.yml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,33 @@ jobs:
100100
title: Types Coverage
101101
delete-old-comments: true
102102

103+
# What the CSS and HTML printers owe whatever they printed, which no
104+
# comparison against another tool can see: being a few bytes off its own best
105+
# is not being worse than a rival. Needs no install and no submodule, so it
106+
# runs in seconds on every pull request.
107+
invariants:
108+
runs-on: ubuntu-latest
109+
steps:
110+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
111+
112+
- name: Use Node.js
113+
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
114+
with:
115+
node-version: lts/*
116+
cache: yarn
117+
118+
- run: yarn --frozen-lockfile
119+
120+
- name: CSS printer invariants
121+
run: yarn test:invariants:css
122+
123+
# A CSS finding must not hide an HTML one: each names a repro of its own
124+
# and both are read in the same sitting. `!cancelled()` rather than
125+
# `always()`, so a cancelled run stops here instead of sweeping again.
126+
- name: HTML printer invariants
127+
if: ${{ !cancelled() }}
128+
run: yarn test:invariants:html
129+
103130
validate-legacy-node:
104131
runs-on: ubuntu-latest
105132
steps:

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ The directory listings below are the canonical map of the repository. **Whenever
137137
- `lib/watch/` — Watch mode: the watching handles a compiler returns, and `WatchIgnorePlugin`.
138138
- `hot/` — Runtime code shipped to browsers for HMR (browser-side, not Node tooling).
139139
- `bin/` — `webpack` CLI entry point.
140-
- `tooling/` — Repo-internal scripts: build/codegen (runtime/wasm generators, hash-debug tool, and `generate-types.js`, the one entry point and one file for everything derived from `schemas/**/*.json` — it reads each schema once, emits that schema's declaration and its precompiled validator, then emits `types.d.ts`, so ordering is internal and one check run names every stale output) invoked by `yarn fix:special`, plus standalone analysis tools such as `compare-css-tools.js` / `compare-html-tools.js` / `compare-js-tools.js` (`yarn benchmark:css-tools`, `yarn benchmark:html-tools`, `yarn benchmark:js-tools`), which share the measuring harness in `compare-tools-harness.js`. Those three need no arguments and no reading of their source: each runs what webpack owns for that language and the ecosystem's equivalents over popular framework stylesheets, real documents and shipped JavaScript bundles, printing **three tables per fixture** — parsing alone, parsing and printing readably (`beautify`), and parsing and printing minified (`minify`) — so what a parse costs is separated from what the printing and the transforms on top of it cost. Every table reports best-of-3 wall and cpu ms and the worker's own peak RSS (each tool × fixture measured in its own process, so the numbers are attributable; read from `/proc/self/status`, since Linux carries `maxRSS` across `fork`+`exec` and a worker asking for its own would report the parent's). **Read wall and cpu together**: cpu above wall is a tool using more than one core (V8's background threads, a native thread pool), cpu below it is a tool waiting rather than computing. A tool that works in a service process of its own says so in its name and reports `-` for cpu and peak, which are spent where nothing here can see them — esbuild is the one today. The two printing tables add output size raw and under gzip/brotli/zstd (the `test:size` settings) and whether the output lost classes / changed the DOM / stopped naming a property ("rejects it" rows mean the tool errored on that input), plus what printing the output a second time moved (`2nd`). The JavaScript one is shaped by webpack owning a parser there and no printer: webpack has a row in the parse table only, and that table's last column holds every ESTree parser against acorn's tree and names the first node where the two differ — which is how a divergence in `lib/javascript/syntax.js` is caught — while a parser answering in a dialect of its own reads as `own dialect` rather than as a disagreement. A round-trip printer that reformats nothing — postcss for CSS, parse5 for HTML — sits in the `beautify` table as the floor the others are read against. `FIXTURE=`, `TOOL=` and `STAGE=` narrow a run to matching rows. They install the packages they compare against into `node_modules/.cache/` on first run rather than into webpack's dependencies; expect the first run to install for a minute and every full run to take upwards of ten. `type-coverage.js` (`yarn types:cover`) reports how much of `lib/` is precisely typed. `find-deep-webpack-imports.js` (`yarn find-deep-imports`) answers which `webpack/lib/…` paths the published ecosystem imports directly: it ranks the most downloaded `webpack`, `webpack-plugin` and `webpack-loader` packages off the registry's search endpoint — which carries weekly downloads with each hit, so `api.npmjs.org` is never needed — then reads each one's tarball rather than installing it, so no lifecycle script of a stranger's package runs. It counts a path only where it is imported, never a bare string, because a package that bundled webpack carries webpack's own `makeSerializable` requests and imports none of them. What it finds is kept in `tooling/deep-webpack-imports.json`, which `--write` refreshes and whose `removed` map names the paths no webpack 5 build can reach with the reason — deleted with the webpack 4 API, imported only by a package that is webpack 4 only, or probed for inside a `try` to detect webpack 4, where a re-export would pick the wrong branch — so only a genuine break fails. `--check` reads that record and nothing else — no network, and no install, so the `Deep Imports` job runs it on every pull request in under a second, comments what broke and what imports it, and fails; it names the packages and the downloads behind each one, and retracts the comment once the paths resolve again; `test/unitCases/deepPathShims.unittest.js` asserts the same thing off the same record, so a move out of `lib/` root learns it owes a re-export from a test rather than from a bug report. `COUNT=` sets how many packages per keyword (default 200), and a package the broad keyword shares with a narrow one is scanned once; tarballs cache under `node_modules/.cache/`, so a re-run costs nothing. Only the collecting half needs the network. `measure-color-agreement.js` (`yarn measure:color-agreement`) is the third: it asks a real browser for its own color conversions rather than for a pixel, and prints how far they sit from webpack's — which is where the rounding margins in `lib/css/syntax.js` and the list of spaces an engine reads through another transfer come from. Re-run it (a few seconds; `PUPPETEER_EXECUTABLE_PATH` picks the binary) rather than adjusting either by hand. **The CSS and HTML comparisons open with a section no one has to ask for**: before the install, each holds webpack's own printer to what it owes whatever it printed, over `test/**/*.css` / `test/**/*.html` plus its own fixtures and whatever the cache already holds, in seconds rather than minutes. `--invariants` runs that section and stops, for a caller that wants the relations without the comparison behind them. Two relations, under each option set the script's own webpack rows are measured with: minifying an already-minified source changes nothing, and (HTML) how a value was spelled does not decide what it minifies to. This is the shape of defect a comparison cannot see, because being a few bytes off its own best is not being worse than another tool: `method=GET` folding only where the source quoted it went unnoticed until this sweep, which is what #22095 fixed. A respelling is lexical (a delimiter, a character reference, the case of a name) and is checked against webpack's own tokenizer before use, so a mutation that moved the document is dropped rather than reported; whitespace inside a tag is deliberately not one, since a tag nothing beats is echoed as written. Each finding is bisected to what carries it and re-run on the enclosing tag alone, so the report names a repro, and groups by it — one printer defect reaches hundreds of pages. `FIXTURE=`, `RELATION=`, `PRESET=` and `SPELLING=` narrow a run. `--invariants` exits non-zero while any finding stands and findings stand today, so read it rather than gating on it, and no embedded body is minified: the CSS minifier has a fixed point of its own and reaching it here would report every page holding a `<style>`. The same question is asked of every other tool in the comparison's own tables, where the `2nd` column is what a second pass over the tool's own output moved — `-` being the answer a printer that is done printing gives.
140+
- `tooling/` — Repo-internal scripts: build/codegen (runtime/wasm generators, hash-debug tool, and `generate-types.js`, the one entry point and one file for everything derived from `schemas/**/*.json` — it reads each schema once, emits that schema's declaration and its precompiled validator, then emits `types.d.ts`, so ordering is internal and one check run names every stale output) invoked by `yarn fix:special`, plus standalone analysis tools such as `compare-css-tools.js` / `compare-html-tools.js` / `compare-js-tools.js` (`yarn benchmark:css-tools`, `yarn benchmark:html-tools`, `yarn benchmark:js-tools`), which share the measuring harness in `compare-tools-harness.js`. Those three need no arguments and no reading of their source: each runs what webpack owns for that language and the ecosystem's equivalents over popular framework stylesheets, real documents and shipped JavaScript bundles, printing **three tables per fixture** — parsing alone, parsing and printing readably (`beautify`), and parsing and printing minified (`minify`) — so what a parse costs is separated from what the printing and the transforms on top of it cost. Every table reports best-of-3 wall and cpu ms and the worker's own peak RSS (each tool × fixture measured in its own process, so the numbers are attributable; read from `/proc/self/status`, since Linux carries `maxRSS` across `fork`+`exec` and a worker asking for its own would report the parent's). **Read wall and cpu together**: cpu above wall is a tool using more than one core (V8's background threads, a native thread pool), cpu below it is a tool waiting rather than computing. A tool that works in a service process of its own says so in its name and reports `-` for cpu and peak, which are spent where nothing here can see them — esbuild is the one today. The two printing tables add output size raw and under gzip/brotli/zstd (the `test:size` settings) and whether the output lost classes / changed the DOM / stopped naming a property ("rejects it" rows mean the tool errored on that input), plus what printing the output a second time moved (`2nd`). The JavaScript one is shaped by webpack owning a parser there and no printer: webpack has a row in the parse table only, and that table's last column holds every ESTree parser against acorn's tree and names the first node where the two differ — which is how a divergence in `lib/javascript/syntax.js` is caught — while a parser answering in a dialect of its own reads as `own dialect` rather than as a disagreement. A round-trip printer that reformats nothing — postcss for CSS, parse5 for HTML — sits in the `beautify` table as the floor the others are read against. `FIXTURE=`, `TOOL=` and `STAGE=` narrow a run to matching rows. They install the packages they compare against into `node_modules/.cache/` on first run rather than into webpack's dependencies; expect the first run to install for a minute and every full run to take upwards of ten. `type-coverage.js` (`yarn types:cover`) reports how much of `lib/` is precisely typed. `find-deep-webpack-imports.js` (`yarn find-deep-imports`) answers which `webpack/lib/…` paths the published ecosystem imports directly: it ranks the most downloaded `webpack`, `webpack-plugin` and `webpack-loader` packages off the registry's search endpoint — which carries weekly downloads with each hit, so `api.npmjs.org` is never needed — then reads each one's tarball rather than installing it, so no lifecycle script of a stranger's package runs. It counts a path only where it is imported, never a bare string, because a package that bundled webpack carries webpack's own `makeSerializable` requests and imports none of them. What it finds is kept in `tooling/deep-webpack-imports.json`, which `--write` refreshes and whose `removed` map names the paths no webpack 5 build can reach with the reason — deleted with the webpack 4 API, imported only by a package that is webpack 4 only, or probed for inside a `try` to detect webpack 4, where a re-export would pick the wrong branch — so only a genuine break fails. `--check` reads that record and nothing else — no network, and no install, so the `Deep Imports` job runs it on every pull request in under a second, comments what broke and what imports it, and fails; it names the packages and the downloads behind each one, and retracts the comment once the paths resolve again; `test/unitCases/deepPathShims.unittest.js` asserts the same thing off the same record, so a move out of `lib/` root learns it owes a re-export from a test rather than from a bug report. `COUNT=` sets how many packages per keyword (default 200), and a package the broad keyword shares with a narrow one is scanned once; tarballs cache under `node_modules/.cache/`, so a re-run costs nothing. Only the collecting half needs the network. `measure-color-agreement.js` (`yarn measure:color-agreement`) is the third: it asks a real browser for its own color conversions rather than for a pixel, and prints how far they sit from webpack's — which is where the rounding margins in `lib/css/syntax.js` and the list of spaces an engine reads through another transfer come from. Re-run it (a few seconds; `PUPPETEER_EXECUTABLE_PATH` picks the binary) rather than adjusting either by hand. **The CSS and HTML comparisons open with a section no one has to ask for**: before the install, each holds webpack's own printer to what it owes whatever it printed, over `test/**/*.css` / `test/**/*.html` plus its own fixtures and whatever the cache already holds, in seconds rather than minutes. `--invariants` runs that section and stops, for a caller that wants the relations without the comparison behind them. Two relations, under each option set the script's own webpack rows are measured with: minifying an already-minified source changes nothing, and (HTML) how a value was spelled does not decide what it minifies to. This is the shape of defect a comparison cannot see, because being a few bytes off its own best is not being worse than another tool: `method=GET` folding only where the source quoted it went unnoticed until this sweep, which is what #22095 fixed. A respelling is lexical (a delimiter, a character reference, the case of a name) and is checked against webpack's own tokenizer before use, so a mutation that moved the document is dropped rather than reported; whitespace inside a tag is deliberately not one, since a tag nothing beats is echoed as written, and a tag another language writes into is skipped whole, since `=""` on a `{% endif %}` restates no value. Each finding is bisected to what carries it and re-run on the enclosing tag alone, so the report names a repro, and groups by it — one printer defect reaches hundreds of pages. `FIXTURE=`, `RELATION=`, `PRESET=` and `SPELLING=` narrow a run. `--invariants` exits non-zero on any finding, which is what the `invariants` job gates every pull request on (`yarn test:invariants`, or `:css` / `:html` for one of them) — a relation is cheap to hold and a regression in one is a defect, so it fails rather than reporting. A divergence the printer owes nothing for is carried in the script's own `EXPECTED` table with the reason beside it, never suppressed by a passing gate, and an entry there that stops matching is itself a finding, so a fix retires its expectation rather than leaving it to rot. No embedded body is minified: the CSS minifier has a fixed point of its own and reaching it here would report every page holding a `<style>`. The same question is asked of every other tool in the comparison's own tables, where the `2nd` column is what a second pass over the tool's own output moved — `-` being the answer a printer that is done printing gives.
141141
- `assembly/` — WebAssembly source for the hash function.
142142
- `setup/` — One-time setup. `setup.js` (`yarn setup`) is the only entry point and picks its own path: a contributor at a terminal gets the interactive one, which installs yarn when it is missing and links through yarn's registry, while everything else gets the non-interactive one — it verifies the lockfile instead of rewriting it, installs no global yarn, and links the checkout in as `node_modules/webpack` without touching yarn's machine-global registry. What it reads is both streams being a terminal plus an unset `CI`, never a list of vendor variables, so an agent nobody has heard of yet takes the safe path — but one that allocates a PTY reads as a contributor, and should set `WEBPACK_SETUP=automated`, which with `interactive` forces either path. Safe to re-run.
143143

‎lib/html/syntax.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4304,7 +4304,8 @@ const _finishMap = (text, map, last, rawLength) => {
43044304
* unchanged when nothing needs escaping.
43054305
* @param {string} s string to escape
43064306
* @param {number=} delimiter the quote the value is written in, `"` by default
4307-
* @param {boolean=} minimal leave an `&` no reference can start after it bare
4307+
* @param {boolean=} minimal leave an `&` no reference can start after it bare,
4308+
* and U+00A0 literal, as `_escapeTextContent` does for a text node
43084309
* @returns {string} HTML attribute-safe string
43094310
*/
43104311
const escapeAttribute = (s, delimiter, minimal) => {
@@ -4313,7 +4314,7 @@ const escapeAttribute = (s, delimiter, minimal) => {
43134314
if (
43144315
!s.includes("&") &&
43154316
!s.includes(quote === CC_APOSTROPHE ? "'" : '"') &&
4316-
!s.includes("\u00A0") &&
4317+
(minimal === true || !s.includes("\u00A0")) &&
43174318
!s.includes("\n") &&
43184319
!s.includes("\r")
43194320
) {
@@ -4345,6 +4346,13 @@ const escapeAttribute = (s, delimiter, minimal) => {
43454346
rep = "&#39;";
43464347
break;
43474348
case CC_NO_BREAK_SPACE:
4349+
// WHY: the minifier keeps it literal, so that a value's own spelling
4350+
// does not decide the output: a source writing the character and one
4351+
// writing `&nbsp;` are the same attribute and print as one. Generated
4352+
// markup still escapes it, matching `escapeText` against
4353+
// `_escapeTextContent` on the text side. Both spellings are the same
4354+
// DOM, and the literal is the shorter of the two.
4355+
if (minimal === true) continue;
43484356
rep = "&nbsp;";
43494357
break;
43504358
case CC_LF:

‎package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
"build:examples": "cd examples && node buildAll.js",
5555
"benchmark": "node --max-old-space-size=6144 --experimental-vm-modules --trace-deprecation --hash-seed=1 --random-seed=1 --no-opt --predictable --predictable-gc-schedule --interpreted-frames-native-stack --allow-natives-syntax --expose-gc --no-concurrent-sweeping ./test/BenchmarkTestCases.benchmark.mjs",
5656
"playground": "webpack serve --config test/hotPlayground/webpack.config.js",
57+
"test:invariants": "yarn test:invariants:css && yarn test:invariants:html",
58+
"test:invariants:css": "node tooling/compare-css-tools.js --invariants",
59+
"test:invariants:html": "node tooling/compare-html-tools.js --invariants",
5760
"benchmark:css-tools": "node tooling/compare-css-tools.js",
5861
"benchmark:css-tools:setup": "node tooling/compare-css-tools.js --setup",
5962
"benchmark:html-tools": "node tooling/compare-html-tools.js",

0 commit comments

Comments
 (0)