mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 09:28:29 +00:00
api/create-filename: relax sanitizeString and use fullwidth replacements
This commit is contained in:
parent
f36c749692
commit
1f03b61edc
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user