api/create-filename: relax sanitizeString and use fullwidth replacements

This commit is contained in:
jj 2025-05-23 07:11:28 +00:00
parent f36c749692
commit 1f03b61edc
No known key found for this signature in database

View File

@ -1,10 +1,24 @@
const illegalCharacters = ['}', '{', '%', '>', '<', '^', ';', ':', '`', '$', '"', "@", '=', '?', '|', '*']; // Characters that are disallowed on Windows:
// https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
const characterMap = {
'<': '',
'>': '',
':': '',
'"': '',
'/': '',
'\\': '',
'|': '',
'?': '',
'*': ''
};
const sanitizeString = (string) => { export const sanitizeString = (string) => {
for (const i in illegalCharacters) { string = string.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
string = string.replaceAll("/", "_").replaceAll("\\", "_")
.replaceAll(illegalCharacters[i], '') for (const [ char, replacement ] of Object.entries(characterMap)) {
string = string.replaceAll(char, replacement);
} }
return string; return string;
} }