From caaaee246048c9b3ecd5e6bef0d9d06a535aa597 Mon Sep 17 00:00:00 2001 From: Kishore <42832651+kishore03109@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:39:46 +0800 Subject: [PATCH 1/2] fix(media): should not have files that begin with underscore --- src/components/MediaSettingsModal/MediaSettingsSchema.jsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/MediaSettingsModal/MediaSettingsSchema.jsx b/src/components/MediaSettingsModal/MediaSettingsSchema.jsx index f89b85d99..98758924e 100644 --- a/src/components/MediaSettingsModal/MediaSettingsSchema.jsx +++ b/src/components/MediaSettingsModal/MediaSettingsSchema.jsx @@ -27,6 +27,13 @@ export const MediaSettingsSchema = (existingTitlesArray = []) => return (value.match(/\./g) || []).length <= 1 } ) + .test( + "File not supported", + "File names cannot begin with an underscore", + (value) => { + return !value.startsWith("_") + } + ) .min( MEDIA_SETTINGS_TITLE_MIN_LENGTH, `Title must be longer than ${MEDIA_SETTINGS_TITLE_MIN_LENGTH} characters` From 724a5d7ebb08e54f52168dc3e4859dbf56f8f86d Mon Sep 17 00:00:00 2001 From: Kishore <42832651+kishore03109@users.noreply.github.com> Date: Tue, 5 Mar 2024 14:02:35 +0800 Subject: [PATCH 2/2] fix(images): should begin with letter --- src/components/MediaSettingsModal/MediaSettingsSchema.jsx | 4 ++-- src/hooks/mediaHooks/useCreateMultipleMedia.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/MediaSettingsModal/MediaSettingsSchema.jsx b/src/components/MediaSettingsModal/MediaSettingsSchema.jsx index 98758924e..26f6fbae1 100644 --- a/src/components/MediaSettingsModal/MediaSettingsSchema.jsx +++ b/src/components/MediaSettingsModal/MediaSettingsSchema.jsx @@ -29,9 +29,9 @@ export const MediaSettingsSchema = (existingTitlesArray = []) => ) .test( "File not supported", - "File names cannot begin with an underscore", + "File names must begin with a letter or number", (value) => { - return !value.startsWith("_") + return /^[a-zA-Z0-9]/.test(value) } ) .min( diff --git a/src/hooks/mediaHooks/useCreateMultipleMedia.ts b/src/hooks/mediaHooks/useCreateMultipleMedia.ts index 58f71e697..fe10cf6e2 100644 --- a/src/hooks/mediaHooks/useCreateMultipleMedia.ts +++ b/src/hooks/mediaHooks/useCreateMultipleMedia.ts @@ -48,6 +48,8 @@ export const useCreateMultipleMedia = ( // with a safe replacement character newFileName: `${getFileName(file.name) .replaceAll(/[\W\s]/g, "_") + // Remove any leading underscores + .replace(/^_+/g, "") .trim()}.${getFileExt(file.name)}`, })) )