mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[FileUpload] Allow special characters in file names (#217361)
## Summary This PR adds the ability for file names to have special characters. Closes: #210312
This commit is contained in:
parent
8c08db126c
commit
94f210dc4c
3 changed files with 3 additions and 24 deletions
|
@ -18,13 +18,13 @@ describe('parseFileName', () => {
|
|||
|
||||
test(' Something_* really -=- strange.abc.wav', () => {
|
||||
expect(parseFileName(' Something_* really -=- strange.abc.wav')).toEqual({
|
||||
name: 'Something__ really ___ strange_abc',
|
||||
name: 'Something_* really -=- strange.abc',
|
||||
});
|
||||
});
|
||||
|
||||
test('!@#$%^&*()', () => {
|
||||
expect(parseFileName('!@#$%^&*()')).toEqual({
|
||||
name: '__________',
|
||||
name: '!@#$%^&*()',
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -14,9 +14,6 @@ interface Result {
|
|||
export function parseFileName(fileName: string): Result {
|
||||
const withoutExt = fileName.substring(0, fileName.lastIndexOf('.')) || fileName;
|
||||
return {
|
||||
name: withoutExt
|
||||
.trim()
|
||||
.slice(0, 256)
|
||||
.replace(/[^a-z0-9\s]/gi, '_'), // replace invalid chars
|
||||
name: withoutExt.trim().slice(0, 256),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -9,38 +9,20 @@
|
|||
|
||||
import { schema, Type } from '@kbn/config-schema';
|
||||
|
||||
const ALPHA_NUMERIC_WITH_SPACES_REGEX = /^[a-z0-9\s_]+$/i;
|
||||
const ALPHA_NUMERIC_WITH_SPACES_EXT_REGEX = /^[a-z0-9\s\._]+$/i;
|
||||
|
||||
function alphanumericValidation(v: string) {
|
||||
return ALPHA_NUMERIC_WITH_SPACES_REGEX.test(v)
|
||||
? undefined
|
||||
: 'Only alphanumeric characters are allowed as file names';
|
||||
}
|
||||
|
||||
function alphanumericWithExtValidation(v: string) {
|
||||
return ALPHA_NUMERIC_WITH_SPACES_EXT_REGEX.test(v)
|
||||
? undefined
|
||||
: 'Only alphanumeric characters, spaces (" "), dots (".") and underscores ("_") are allowed';
|
||||
}
|
||||
|
||||
export const fileName = schema.string({
|
||||
minLength: 1,
|
||||
maxLength: 256,
|
||||
validate: alphanumericValidation,
|
||||
});
|
||||
|
||||
export const fileNameWithExt = schema.string({
|
||||
minLength: 1,
|
||||
maxLength: 256,
|
||||
validate: alphanumericWithExtValidation,
|
||||
});
|
||||
|
||||
export const fileAlt = schema.maybe(
|
||||
schema.string({
|
||||
minLength: 1,
|
||||
maxLength: 256,
|
||||
validate: alphanumericValidation,
|
||||
})
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue