Skip to content

Commit 94f210d

Browse files
[FileUpload] Allow special characters in file names (#217361)
## Summary This PR adds the ability for file names to have special characters. Closes: #210312
1 parent 8c08db1 commit 94f210d

File tree

3 files changed

+3
-24
lines changed

3 files changed

+3
-24
lines changed

src/platform/packages/shared/shared-ux/file/file_upload/impl/src/util/parse_file_name.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ describe('parseFileName', () => {
1818

1919
test(' Something_* really -=- strange.abc.wav', () => {
2020
expect(parseFileName(' Something_* really -=- strange.abc.wav')).toEqual({
21-
name: 'Something__ really ___ strange_abc',
21+
name: 'Something_* really -=- strange.abc',
2222
});
2323
});
2424

2525
test('!@#$%^&*()', () => {
2626
expect(parseFileName('!@#$%^&*()')).toEqual({
27-
name: '__________',
27+
name: '!@#$%^&*()',
2828
});
2929
});
3030

src/platform/packages/shared/shared-ux/file/file_upload/impl/src/util/parse_file_name.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ interface Result {
1414
export function parseFileName(fileName: string): Result {
1515
const withoutExt = fileName.substring(0, fileName.lastIndexOf('.')) || fileName;
1616
return {
17-
name: withoutExt
18-
.trim()
19-
.slice(0, 256)
20-
.replace(/[^a-z0-9\s]/gi, '_'), // replace invalid chars
17+
name: withoutExt.trim().slice(0, 256),
2118
};
2219
}

src/platform/plugins/shared/files/server/routes/common_schemas.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,20 @@
99

1010
import { schema, Type } from '@kbn/config-schema';
1111

12-
const ALPHA_NUMERIC_WITH_SPACES_REGEX = /^[a-z0-9\s_]+$/i;
13-
const ALPHA_NUMERIC_WITH_SPACES_EXT_REGEX = /^[a-z0-9\s\._]+$/i;
14-
15-
function alphanumericValidation(v: string) {
16-
return ALPHA_NUMERIC_WITH_SPACES_REGEX.test(v)
17-
? undefined
18-
: 'Only alphanumeric characters are allowed as file names';
19-
}
20-
21-
function alphanumericWithExtValidation(v: string) {
22-
return ALPHA_NUMERIC_WITH_SPACES_EXT_REGEX.test(v)
23-
? undefined
24-
: 'Only alphanumeric characters, spaces (" "), dots (".") and underscores ("_") are allowed';
25-
}
26-
2712
export const fileName = schema.string({
2813
minLength: 1,
2914
maxLength: 256,
30-
validate: alphanumericValidation,
3115
});
3216

3317
export const fileNameWithExt = schema.string({
3418
minLength: 1,
3519
maxLength: 256,
36-
validate: alphanumericWithExtValidation,
3720
});
3821

3922
export const fileAlt = schema.maybe(
4023
schema.string({
4124
minLength: 1,
4225
maxLength: 256,
43-
validate: alphanumericValidation,
4426
})
4527
);
4628

0 commit comments

Comments
 (0)