From 74aa4e087e685df69ec5866eef0e082e276ef4ea 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] 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 98758924e2..26f6fbae11 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 58f71e6979..fe10cf6e27 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)}`, })) )