From 9d2156d34678cf8a794a3fa1065778af770cb982 Mon Sep 17 00:00:00 2001 From: devland Date: Wed, 4 Dec 2024 09:29:53 +0100 Subject: [PATCH] fix validateFileForUpload for non-media files --- api.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/api.js b/api.js index 01b112fd..3366100c 100644 --- a/api.js +++ b/api.js @@ -665,24 +665,16 @@ const validateFileForUpload = (uploadFieldType, mimeType, extension) => { const allowedExtensions = config.files.patterns.allowed.toString() .replace(/[^a-zA-Z0-9|]/g, '') .split('|'); - - mimeType = '*'; // Allow allowedExtensions for all mime types - allowed = { mimeType : allowedExtensions }; + allowed = { '*': allowedExtensions }; // Allow allowedExtensions for all mime types break; default: allowed = {}; } - const isExtensionAllowed = (allowed[mimeType] ?? []).includes(extension); - - const message = isExtensionAllowed ? - 'OK' : - `Invalid ${uploadFieldType} file format.`; - - const extensionsToUse = isExtensionAllowed ? - '' : - listExtensions(Object.values(allowed).flat()); + const isExtensionAllowed = (allowed[mimeType] ?? allowed['*'] ?? []).includes(extension); + const message = isExtensionAllowed ? 'OK' : `Invalid ${uploadFieldType} file format.`; + const extensionsToUse = isExtensionAllowed ? '' : listExtensions(Object.values(allowed).flat()); return [message, extensionsToUse].filter(Boolean).join(' '); }