Skip to content

Commit 47d3d1b

Browse files
fix(media-core): normalize GIF content type detection (#96435)
Merged via squash. Prepared head SHA: 82b1396 Co-authored-by: lin-hongkuan <[email protected]> Co-authored-by: vincentkoc <[email protected]> Reviewed-by: @vincentkoc
1 parent 0347ae4 commit 47d3d1b

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

packages/media-core/src/mime.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
FILE_TYPE_SNIFF_MAX_BYTES,
99
imageMimeFromFormat,
1010
isAudioFileName,
11+
isGifMedia,
1112
kindFromMime,
1213
mimeTypeFromFilePath,
1314
normalizeMimeType,
@@ -271,6 +272,29 @@ describe("isAudioFileName", () => {
271272
});
272273
});
273274

275+
describe("isGifMedia", () => {
276+
it.each([
277+
{
278+
opts: { contentType: "image/gif; charset=binary" },
279+
expected: true,
280+
},
281+
{
282+
opts: { contentType: " IMAGE/GIF " },
283+
expected: true,
284+
},
285+
{
286+
opts: { contentType: "image/png" },
287+
expected: false,
288+
},
289+
{
290+
opts: { fileName: "animation.GIF" },
291+
expected: true,
292+
},
293+
] as const)("detects GIF media from normalized metadata %#", ({ opts, expected }) => {
294+
expect(isGifMedia(opts)).toBe(expected);
295+
});
296+
});
297+
274298
describe("normalizeMimeType", () => {
275299
function expectNormalizedMimeCase(
276300
input: Parameters<typeof normalizeMimeType>[0],

packages/media-core/src/mime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export function isGifMedia(opts: {
252252
contentType?: string | null;
253253
fileName?: string | null;
254254
}): boolean {
255-
if (opts.contentType?.toLowerCase() === "image/gif") {
255+
if (normalizeMimeType(opts.contentType) === "image/gif") {
256256
return true;
257257
}
258258
const ext = getFileExtension(opts.fileName);

0 commit comments

Comments
 (0)