fix: support name in Chinese [#3211]

This commit is contained in:
brandon.xiang 2024-10-21 16:46:29 +08:00
parent ac67c4c0d8
commit 0ac735a1e6
2 changed files with 3 additions and 2 deletions

View File

@ -70,13 +70,13 @@ export const safeParseXML = (str, options) => {
} }
}; };
// Remove any characters that are not alphanumeric, spaces, hyphens, or underscores // Remove any characters that are not alphanumeric, spaces, hyphens, underscores, or Chinese characters
export const normalizeFileName = (name) => { export const normalizeFileName = (name) => {
if (!name) { if (!name) {
return name; return name;
} }
const validChars = /[^\w\s-]/g; const validChars = /[^\w\s\u4e00-\u9fa5-]/g;
const formattedName = name.replace(validChars, '-'); const formattedName = name.replace(validChars, '-');
return formattedName; return formattedName;

View File

@ -14,6 +14,7 @@ describe('common utils', () => {
expect(normalizeFileName('hello_world?')).toBe('hello_world-'); expect(normalizeFileName('hello_world?')).toBe('hello_world-');
expect(normalizeFileName('foo/bar/')).toBe('foo-bar-'); expect(normalizeFileName('foo/bar/')).toBe('foo-bar-');
expect(normalizeFileName('foo\\bar\\')).toBe('foo-bar-'); expect(normalizeFileName('foo\\bar\\')).toBe('foo-bar-');
expect(normalizeFileName('hello_world-123中文!@#$%^&*()')).toBe('hello_world-123中文----------');
}); });
}); });