Skip to content

Commit a84d810

Browse files
committed
fix: improve extension validation
1 parent 965fb7a commit a84d810

File tree

5 files changed

+66
-6
lines changed

5 files changed

+66
-6
lines changed

packages/pluggableWidgets/file-uploader-web/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- We improved the file extension validation to allow special characters like dashes and plus signs (e.g., '.tar-gz', '.c++').
12+
13+
- We clarified error messages for invalid file extensions to better explain the expected format.
14+
915
## [2.2.2] - 2025-07-01
1016

1117
### Fixed

packages/pluggableWidgets/file-uploader-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@mendix/file-uploader-web",
33
"widgetName": "FileUploader",
4-
"version": "2.2.2",
4+
"version": "2.2.3",
55
"description": "",
66
"copyright": "© Mendix Technology BV 2025. All rights reserved.",
77
"license": "Apache-2.0",

packages/pluggableWidgets/file-uploader-web/src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="FileUploader" version="2.2.2" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="FileUploader" version="2.2.3" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="FileUploader.xml" />
66
</widgetFiles>

packages/pluggableWidgets/file-uploader-web/src/utils/__tests__/parseAllowedFormats.spec.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,40 @@ describe("parseAllowedFormats", () => {
9595
"Value 'application-pdf' is not recognized. Accepted format: 'image/jpeg'"
9696
);
9797
});
98+
test("handles extensions with special characters like dashes and plus signs", () => {
99+
const input: AllowedFileFormatsType[] = [
100+
{
101+
configMode: "advanced",
102+
typeFormatDescription: dynamicValue("special-extensions"),
103+
predefinedType: "pdfFile",
104+
mimeType: "application/x-custom",
105+
extensions: ".tar-gz,.js-map,.c++"
106+
}
107+
];
108+
109+
expect(parseAllowedFormats(input)).toEqual([
110+
{
111+
description: "special-extensions",
112+
entries: [["application/x-custom", [".tar-gz", ".js-map", ".c++"]]]
113+
}
114+
]);
115+
});
116+
test("throws on extension without leading dot", () => {
117+
const input: AllowedFileFormatsType[] = [
118+
{
119+
configMode: "advanced",
120+
typeFormatDescription: dynamicValue("test"),
121+
predefinedType: "pdfFile",
122+
mimeType: "text/*",
123+
extensions: ".txt,pdf"
124+
}
125+
];
126+
127+
expect(() => parseAllowedFormats(input)).toThrow(
128+
"Value 'pdf' is not recognized. Extension must start with a dot and contain only valid filename characters"
129+
);
130+
});
131+
98132
test("throws on incorrect extension format", () => {
99133
const input: AllowedFileFormatsType[] = [
100134
{
@@ -106,6 +140,24 @@ describe("parseAllowedFormats", () => {
106140
}
107141
];
108142

109-
expect(() => parseAllowedFormats(input)).toThrow("Value 'abc' is not recognized. Accepted format: '.pdf'");
143+
expect(() => parseAllowedFormats(input)).toThrow(
144+
"Value 'abc' is not recognized. Extension must start with a dot and contain only valid filename characters"
145+
);
146+
});
147+
148+
test("throws on extension with dot in the middle", () => {
149+
const input: AllowedFileFormatsType[] = [
150+
{
151+
configMode: "advanced",
152+
typeFormatDescription: dynamicValue("test"),
153+
predefinedType: "pdfFile",
154+
mimeType: "text/*",
155+
extensions: ".txt,.config.json"
156+
}
157+
];
158+
159+
expect(() => parseAllowedFormats(input)).toThrow(
160+
"Value '.config.json' is not recognized. Extension must start with a dot and contain only valid filename characters"
161+
);
110162
});
111163
});

packages/pluggableWidgets/file-uploader-web/src/utils/parseAllowedFormats.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ function parseExtensionsList(config: string): string[] {
5959
.map(c => c.trim())
6060
.filter(c => c)
6161
.map(c => {
62-
if (/^\.\w+$/.test(c)) {
63-
// ".ext" string
62+
if (/^\.[^\/\\?*<>|:".]+$/.test(c)) {
63+
// ".ext" string - allowing most characters except those invalid in filenames
6464
return c;
6565
}
6666

67-
throw new Error(`Value '${c}' is not recognized. Accepted format: '.pdf'`);
67+
throw new Error(
68+
`Value '${c}' is not recognized. Extension must start with a dot and contain only valid filename characters (e.g. '.pdf', '.doc', '.tar-gz')`
69+
);
6870
});
6971
}

0 commit comments

Comments
 (0)