mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 15:33:11 +01:00
feat(utils): improve normalizeFileName to support Unicode characters
- Update the `normalizeFileName` function to use a RegExp that supports Unicode characters - Add tests for `normalizeFileName` with various Unicode languages
This commit is contained in:
parent
6b668aaebe
commit
f21d78f887
@ -68,10 +68,9 @@ export const normalizeFileName = (name) => {
|
||||
return name;
|
||||
}
|
||||
|
||||
const validChars = /[^\w\s-]/g;
|
||||
const formattedName = name.replace(validChars, '-');
|
||||
|
||||
return formattedName;
|
||||
// Use Unicode character classes to match alphanumeric characters, spaces, hyphens, and underscores
|
||||
const validChars = new RegExp('[^\\p{L}\\p{M}\\p{N}\\s_-]', 'gu');
|
||||
return name.replace(validChars, '-');
|
||||
};
|
||||
|
||||
export const getContentType = (headers) => {
|
||||
|
@ -15,5 +15,16 @@ describe('common utils', () => {
|
||||
expect(normalizeFileName('foo/bar/')).toBe('foo-bar-');
|
||||
expect(normalizeFileName('foo\\bar\\')).toBe('foo-bar-');
|
||||
});
|
||||
it('should support unicode', () => {
|
||||
// more unicode languages
|
||||
expect(normalizeFileName('你好世界!?@#$%^&*()')).toBe('你好世界-----------');
|
||||
expect(normalizeFileName('こんにちは世界!?@#$%^&*()')).toBe('こんにちは世界-----------');
|
||||
expect(normalizeFileName('안녕하세요 세계!?@#$%^&*()')).toBe('안녕하세요 세계-----------');
|
||||
expect(normalizeFileName('مرحبا بالعالم!?@#$%^&*()')).toBe('مرحبا بالعالم-----------');
|
||||
expect(normalizeFileName('Здравствуй мир!?@#$%^&*()')).toBe('Здравствуй мир-----------');
|
||||
expect(normalizeFileName('नमस्ते दुनिया!?@#$%^&*()')).toBe('नमस्ते दुनिया-----------');
|
||||
expect(normalizeFileName('สวัสดีชาวโลก!?@#$%^&*()')).toBe('สวัสดีชาวโลก-----------');
|
||||
expect(normalizeFileName('γειά σου κόσμος!?@#$%^&*()')).toBe('γειά σου κόσμος-----------');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user