Skip to content

fix(utils/mime): extend charset to xml-based mime types#4909

Open
kasharkzy wants to merge 2 commits into
honojs:mainfrom
kasharkzy:fix/charset-xml-mime-types
Open

fix(utils/mime): extend charset to xml-based mime types#4909
kasharkzy wants to merge 2 commits into
honojs:mainfrom
kasharkzy:fix/charset-xml-mime-types

Conversation

@kasharkzy
Copy link
Copy Markdown

@kasharkzy kasharkzy commented May 5, 2026

The getMimeType() function was using startsWith('text') to decide when to append ; charset=utf-8 to a MIME type, that heuristic misses types like image/svg+xml, application/xhtml+xml and application/xml, which are all textual formats where charset matters for correct decoding.

This replaces the prefix check with a condition that covers three cases:
text/ prefix, per RFC 2046
+xml structured syntax suffix, per RFC 6839
application/xml explicitly, per RFC 7303 §8.5

The change is a single-line diff in mime.ts, with three new assertions in
mime.test.ts covering the previously untested types.

Fixes #4510

kasharkzy and others added 2 commits May 5, 2026 12:51
The startsWith('text') check was missing charset on image/svg+xml,
application/xhtml+xml and application/xml. Replaced with a condition
grounded in RFC 2046 (text/*), RFC 6839 (+xml structured syntax suffix)
and RFC 7303 §8.5 (application/xml).
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.00%. Comparing base (8f027e5) to head (428aa67).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4909   +/-   ##
=======================================
  Coverage   93.00%   93.00%           
=======================================
  Files         177      177           
  Lines       11900    11901    +1     
  Branches     3568     3570    +2     
=======================================
+ Hits        11068    11069    +1     
  Misses        832      832           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Proposal to change to specifying charset parameter individually for each MIME type

1 participant