From fcea2314bcefbbbd9ab3472b01fce478578b90ae Mon Sep 17 00:00:00 2001 From: suiso67 Date: Sat, 14 Dec 2024 11:51:01 +0900 Subject: [PATCH] feat: handle korean as a valid file name component --- packages/bruno-app/src/utils/common/index.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/bruno-app/src/utils/common/index.js b/packages/bruno-app/src/utils/common/index.js index 1244966b..b3de79b5 100644 --- a/packages/bruno-app/src/utils/common/index.js +++ b/packages/bruno-app/src/utils/common/index.js @@ -70,16 +70,26 @@ export const safeParseXML = (str, options) => { } }; -// Remove any characters that are not alphanumeric, spaces, hyphens, or underscores export const normalizeFileName = (name) => { if (!name) { return name; } - const validChars = /[^\w\s-]/g; - const formattedName = name.replace(validChars, '-'); + // alphanumerics, spaces, underscores, hyphens + const baseValidExpression = '\\w\\s-'; + const additionalValidExpressions = [ + 'ㄱ-ㅎ|ㅏ-ㅣ|가-힣', // Korean + ]; - return formattedName; + const validExpression = [ + baseValidExpression, + ...additionalValidExpressions, + ].join('|'); + + const invalidCharRegex = new RegExp(`[^${validExpression}]`, 'g') + const normalizedFileName = name.replace(invalidCharRegex, '-'); + + return normalizedFileName; }; export const getContentType = (headers) => {