adding file name validation

This commit is contained in:
2026-01-05 10:30:26 -07:00
parent 8c01cb2422
commit 767528560c
5 changed files with 63 additions and 48 deletions

View File

@@ -0,0 +1,28 @@
export function validateFileName(fileName: string): string {
if (!fileName || fileName.trim() === "") {
return "Name cannot be empty";
}
const invalidChars = [":", "/", "\\", "*", "?", '"', "<", ">", "|"];
for (const char of fileName) {
if (invalidChars.includes(char)) {
return `Name contains invalid character: "${char}". Please avoid: ${invalidChars.join(
" "
)}`;
}
}
if (fileName !== fileName.trimEnd()) {
return "Name cannot end with whitespace";
}
return "";
}
export function assertValidFileName(fileName: string): void {
const error = validateFileName(fileName);
if (error) {
throw new Error(error);
}
}