Prevent HTML minification from corrupting embedded WASM data - #27509
Open
sbc100 wants to merge 1 commit into
Open
Prevent HTML minification from corrupting embedded WASM data#27509sbc100 wants to merge 1 commit into
sbc100 wants to merge 1 commit into
Conversation
Pass `--ignore-custom-fragments '[]'` to `html-minifier-terser`. By default, `html-minifier-terser` includes custom fragment regexes `/<%[\s\S]*?%>/` and `/<\?[\s\S]*?\?>/` intended for ignoring server-side preprocessor tags (like PHP `<?php ... ?>` or ASP `<% ... %>`). When matching these fragments, `html-minifier-terser` matches surrounding whitespace `\s*` and collapses it. When WASM binary data is embedded in JavaScript inside an HTML file (such as in `-sSINGLE_FILE=1` builds), arbitrary byte sequences in the WASM binary can happen to match `<?...?>` or `<%...%>`. In these cases, `html-minifier-terser` mistakes the binary data for preprocessor tags and collapses surrounding spaces (`0x20` bytes), corrupting the embedded WASM binary payload. Passing `--ignore-custom-fragments '[]'` disables this behavior. It is safe for Emscripten because generated HTML files are standard client-side documents, not server-side PHP/ASP template files containing preprocessor tags. Fixes: emscripten-core#27156
sbc100
force-pushed
the
fix-html-minifier-custom-fragments
branch
from
August 9, 2026 19:15
c5f933d to
ef74478
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pass
--ignore-custom-fragments '[]'tohtml-minifier-terser.By default,
html-minifier-terserincludes custom fragment regexes/<%[\s\S]*?%>/and/<\?[\s\S]*?\?>/intended for ignoring server-sidepreprocessor tags (like PHP
<?php ... ?>or ASP<% ... %>). Whenmatching these fragments,
html-minifier-tersermatches surroundingwhitespace
\s*and collapses it.When WASM binary data is embedded in JavaScript inside an HTML file
(such as in
-sSINGLE_FILE=1builds), arbitrary byte sequences in theWASM binary can happen to match
<?...?>or<%...%>. In these cases,html-minifier-tersermistakes the binary data for preprocessor tagsand collapses surrounding spaces (
0x20bytes), corrupting the embeddedWASM binary payload.
Passing
--ignore-custom-fragments '[]'disables this behavior. It issafe for Emscripten because generated HTML files are standard
client-side documents, not server-side PHP/ASP template files containing
preprocessor tags.
Fixes: #27156