Skip to content
Myr

fix(mime): specify charset parameter per MIME type instead of mechanical detection (#4912)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Per #4510: - Inline `; charset=utf-8` in `_baseMimes` for all text/* entries plus `image/svg+xml`, `application/xhtml+xml`, and `application/xml`, which are XML-based formats that benefit from an explicit charset. - Drop the `if (mimeType.startsWith("text"))` block in `getMimeType`; the charset now lives in the data, not in the lookup logic. Output for text types is unchanged (still "text/<sub>; charset=utf-8"). - Update `getExtension` to compare the base type (the part before the first `;`), so callers can pass either a raw type ("text/html") or one with parameters ("text/html; charset=utf-8") and still get the correct extension back. Tests: 5 mime.test.ts cases pass (3 existing + 2 new) covering the new charset values for svg/xhtml/xml/ics/mjs/css/csv and getExtension with parameters. Closes #4510

authored by Renato Grasso · committed by GitHub · parent cf6ef70 · Browse files · 2 files+36 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+36 added−17 removed

  • tests:+21 added−0 removed
  • other:+15 added−17 removed

2 files+36 added−17 removed

modified:src/utils/mime.test.ts+21 added
modified:src/utils/mime.ts+15 added-17 removed