Skip to content

About

Minimal repro: webpack 5.110 HTML minifier corrupts {% %} template tags inside start tags in copy-webpack-plugin .html assets

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

webpack 5.110 HTML minifier deduplicates the %} delimiter in copied .html

webpack 5.110.0 added a built-in HTML minifier, on by default in mode: 'production'. It re-serializes every .html asset, including files that copy-webpack-plugin passes through unchanged. When such a file contains {% ... %} server-side template statements (the statement delimiter of the Django/Jinja family: Jinja2, Django, Twig, Liquid, Nunjucks, HubSpot HubL), the minifier can drop a %} delimiter and emit invalid markup from valid input. No HTML loader, html-webpack-plugin, or configured minimizer is involved.

Run

npm install
npm run verify   # build, then print each src/*.html next to its dist/ output

Result

== src/corrupt-conditional-attribute.html -> dist/corrupt-conditional-attribute.html ==
  in : <input type="text"{% if required %} required{% endif %}>
  out: <input type=text {% if required %} required{% endif>
== src/corrupt-space-inside-conditional.html -> dist/corrupt-space-inside-conditional.html ==
  in : <div class="btn{% if active %} btn-active{% endif %}"></div>
  out: <div class="btn{% if active %} btn-active{% endif"></div>
== src/survive-space-outside-conditional.html -> dist/survive-space-outside-conditional.html ==
  in : <div class="btn {% if active %}btn-active{% endif %}"></div>
  out: <div class="btn {% if active %}btn-active{% endif %}"></div>

type="text" quote removal is valid HTML minification and is not the problem. The problem is the dropped %}.

Root cause

The minifier (webpack/lib/html/syntax.js) is a spec-compliant HTML parser with no template-syntax awareness. %} tokenizes as a valid HTML attribute name (the attribute-name state accepts every character except whitespace, /, >, and =), so {% if required %} required{% endif %} produces two %} attribute-name tokens. Two mechanisms then drop the repeat:

(Links are pinned to the v5.110.3 commit, so the line numbers stay accurate as the code changes.)

Versions

Byte-identical (correct) output on 5.109.2, the final 5.109.x release, which predates the built-in minifier. Identical corruption on 5.110.0, 5.110.2, and 5.110.3. The break lands at the 5.109 to 5.110 boundary.

About

Minimal repro: webpack 5.110 HTML minifier corrupts {% %} template tags inside start tags in copy-webpack-plugin .html assets

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages