feat: handle korean as a valid file name component

This commit is contained in:
suiso67 2024-12-14 11:51:01 +09:00
parent 57d86eb118
commit fcea2314bc

View File

@ -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) => {