mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 01:18:27 +00:00
api/create-filename: relax sanitizeString and use fullwidth replacements
This commit is contained in:
parent
f36c749692
commit
2eadc3fbd8
@ -1,10 +1,25 @@
|
|||||||
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) {
|
// remove any potential control characters the string might contain
|
||||||
string = string.replaceAll("/", "_").replaceAll("\\", "_")
|
string = string.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
|
||||||
.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