diff --git a/packages/modules/file-uploader/package.json b/packages/modules/file-uploader/package.json index 4b999edc48..6a44fe4a2a 100644 --- a/packages/modules/file-uploader/package.json +++ b/packages/modules/file-uploader/package.json @@ -1,7 +1,7 @@ { "name": "@mendix/file-uploader", "moduleName": "File Uploader module", - "version": "2.2.2", + "version": "2.3.0", "copyright": "© Mendix Technology BV 2025. All rights reserved.", "license": "Apache-2.0", "private": true, diff --git a/packages/pluggableWidgets/file-uploader-web/CHANGELOG.md b/packages/pluggableWidgets/file-uploader-web/CHANGELOG.md index d04ec89b89..b1c19e45ad 100644 --- a/packages/pluggableWidgets/file-uploader-web/CHANGELOG.md +++ b/packages/pluggableWidgets/file-uploader-web/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - We fixed an issue where file uploader can still add more files when refreshed eventhough the number of maximum uploaded files has been reached. +- We improved the file extension validation to allow special characters like dashes and plus signs (e.g., '.tar-gz', '.c++'). + +- We clarified error messages for invalid file extensions to better explain the expected format. + ### Changed - We change the max file configuration to set maximum number of uploaded files through expression. diff --git a/packages/pluggableWidgets/file-uploader-web/src/utils/__tests__/parseAllowedFormats.spec.ts b/packages/pluggableWidgets/file-uploader-web/src/utils/__tests__/parseAllowedFormats.spec.ts index 5d82d46298..cae4020b47 100644 --- a/packages/pluggableWidgets/file-uploader-web/src/utils/__tests__/parseAllowedFormats.spec.ts +++ b/packages/pluggableWidgets/file-uploader-web/src/utils/__tests__/parseAllowedFormats.spec.ts @@ -95,6 +95,40 @@ describe("parseAllowedFormats", () => { "Value 'application-pdf' is not recognized. Accepted format: 'image/jpeg'" ); }); + test("handles extensions with special characters like dashes and plus signs", () => { + const input: AllowedFileFormatsType[] = [ + { + configMode: "advanced", + typeFormatDescription: dynamicValue("special-extensions"), + predefinedType: "pdfFile", + mimeType: "application/x-custom", + extensions: ".tar-gz,.js-map,.c++" + } + ]; + + expect(parseAllowedFormats(input)).toEqual([ + { + description: "special-extensions", + entries: [["application/x-custom", [".tar-gz", ".js-map", ".c++"]]] + } + ]); + }); + test("throws on extension without leading dot", () => { + const input: AllowedFileFormatsType[] = [ + { + configMode: "advanced", + typeFormatDescription: dynamicValue("test"), + predefinedType: "pdfFile", + mimeType: "text/*", + extensions: ".txt,pdf" + } + ]; + + expect(() => parseAllowedFormats(input)).toThrow( + "Value 'pdf' is not recognized. Extension must start with a dot and contain only valid filename characters" + ); + }); + test("throws on incorrect extension format", () => { const input: AllowedFileFormatsType[] = [ { @@ -106,6 +140,24 @@ describe("parseAllowedFormats", () => { } ]; - expect(() => parseAllowedFormats(input)).toThrow("Value 'abc' is not recognized. Accepted format: '.pdf'"); + expect(() => parseAllowedFormats(input)).toThrow( + "Value 'abc' is not recognized. Extension must start with a dot and contain only valid filename characters" + ); + }); + + test("throws on extension with dot in the middle", () => { + const input: AllowedFileFormatsType[] = [ + { + configMode: "advanced", + typeFormatDescription: dynamicValue("test"), + predefinedType: "pdfFile", + mimeType: "text/*", + extensions: ".txt,.config.json" + } + ]; + + expect(() => parseAllowedFormats(input)).toThrow( + "Value '.config.json' is not recognized. Extension must start with a dot and contain only valid filename characters" + ); }); }); diff --git a/packages/pluggableWidgets/file-uploader-web/src/utils/parseAllowedFormats.ts b/packages/pluggableWidgets/file-uploader-web/src/utils/parseAllowedFormats.ts index c3218110d1..a78200785a 100644 --- a/packages/pluggableWidgets/file-uploader-web/src/utils/parseAllowedFormats.ts +++ b/packages/pluggableWidgets/file-uploader-web/src/utils/parseAllowedFormats.ts @@ -59,11 +59,13 @@ function parseExtensionsList(config: string): string[] { .map(c => c.trim()) .filter(c => c) .map(c => { - if (/^\.\w+$/.test(c)) { - // ".ext" string + if (/^\.[^/\\?*<>|:".]+$/.test(c)) { + // ".ext" string - allowing most characters except those invalid in filenames return c; } - throw new Error(`Value '${c}' is not recognized. Accepted format: '.pdf'`); + throw new Error( + `Value '${c}' is not recognized. Extension must start with a dot and contain only valid filename characters (e.g. '.pdf', '.doc', '.tar-gz')` + ); }); }