Vanessa 2026-02-11 21:14:58 +08:00
parent b37d0c1c5b
commit b5c652b821
2 changed files with 8 additions and 36 deletions

View file

@ -719,22 +719,19 @@ export const setNoteBook = (cb?: (notebook: INotebook[]) => void, flashcard = fa
/**
* ".." 穿
*
* @returns 使 / null
* @returns 使 /
*/
export const normalizeStoragePath = (storageName: string): string | null => {
const normalized = storageName.replace(/\\/g, "/");
const parts = normalized.split("/").filter(Boolean);
const parts = storageName.replace(/\\/g, "/").split("/");
const resolved: string[] = [];
for (const part of parts) {
if (part === "..") {
if (resolved.length > 0) {
resolved.pop();
} else {
return null;
}
} else if (part !== ".") {
} else if (part && part !== ".") {
resolved.push(part);
}
}
return resolved.length > 0 ? resolved.join("/") : null;
return resolved.length > 0 ? resolved.join("/") : storageName.replace(/[\/\\]+/g, "");
};