Skip to content

Preserve case of SVG/MathML foreign-content attributes - #284

Open
QQSHI13 wants to merge 1 commit into
wilsonzlin:masterfrom
QQSHI13:fix/svg-foreign-content-case
Open

Preserve case of SVG/MathML foreign-content attributes#284
QQSHI13 wants to merge 1 commit into
wilsonzlin:masterfrom
QQSHI13:fix/svg-foreign-content-case

Conversation

@QQSHI13

@QQSHI13 QQSHI13 commented Aug 6, 2026

Copy link
Copy Markdown

minify-html lowercases every HTML attribute name, which breaks SVG (and would break MathML) foreign content: per the HTML spec, attribute names inside those subtrees are case-sensitive, so <svg viewBox="0 0 24 24"> renders differently from viewbox. Browsers and conformant parsers (e.g. html5lib) preserve the case; minify-html does not.

Repro:

minify("<svg viewBox=\"0 0 24 24\" preserveAspectRatio=\"xMidYMid\"></svg>")
=> <svg viewbox="0 0 24 24" preserveaspectratio=xMidYMid></svg>   (broken)

Changes:

  • Track the SVG namespace during parsing (an svg element enters it, case-insensitive match) and preserve element + attribute name case inside it; HTML keeps lowercasing.
  • Same fix in both implementations (minify-html and minify-html-onepass), since they share the test data.
  • Closing-tag matching is now case-insensitive so </linearGradient> still matches <linearGradient>.
  • Updated the shared test data: viewBox is expected preserved; an uppercase D on <path> is now treated as a distinct attribute (no lowercase-induced value removal).

Tests: cargo test -p minify-html -p minify-html-common -p minify-html-onepass — all green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant