fix(utils/mime): extend charset to xml-based mime types#4909
Open
kasharkzy wants to merge 2 commits into
Open
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
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