Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(media): stop the constructor subtype becoming the file extension

Yudhi Armyndharis6f3631041c07
diff --git a/src/common/media/mime-ext.spec.ts b/src/common/media/mime-ext.spec.ts
index 5bfd8dc40..59d596ab3 100644
--- a/src/common/media/mime-ext.spec.ts
+++ b/src/common/media/mime-ext.spec.ts
@@ -6,6 +6,8 @@ describe('extFromMimetype', () => {
['audio/ogg; codecs=opus', 'ogg'],
['IMAGE/WEBP', 'webp'],
['application/pdf', 'pdf'],
+ ['application/constructor', 'constructor'],
+ ['IMAGE/CONSTRUCTOR', 'constructor'],
])('uses the subtype of %s as the extension', (mimetype, ext) => {
expect(extFromMimetype(mimetype)).toBe(ext);
});
diff --git a/src/common/media/mime-ext.ts b/src/common/media/mime-ext.ts
index 5bd40929e..ad4691eb9 100644
--- a/src/common/media/mime-ext.ts
+++ b/src/common/media/mime-ext.ts
@@ -5,5 +5,6 @@ const MIME_SUBTYPE_EXT_OVERRIDES: Record<string, string> = { jpeg: 'jpg', quickt
export function extFromMimetype(mimetype: string): string {
const subtype = mimetype.split('/')[1]?.split(';')[0]?.trim().toLowerCase();
if (!subtype || !/^[a-z0-9]+$/.test(subtype)) return 'bin';
- return MIME_SUBTYPE_EXT_OVERRIDES[subtype] ?? subtype;
+ // Own keys only: 'constructor' is a legal subtype and an inherited member would come back as the extension.
+ return Object.hasOwn(MIME_SUBTYPE_EXT_OVERRIDES, subtype) ? MIME_SUBTYPE_EXT_OVERRIDES[subtype] : subtype;
}