mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-09 14:12:34 +01:00
🎨 Plugin supports saving data in subdirectories (#17007)
This commit is contained in:
parent
4257986729
commit
b37d0c1c5b
2 changed files with 54 additions and 5 deletions
|
|
@ -715,3 +715,26 @@ export const setNoteBook = (cb?: (notebook: INotebook[]) => void, flashcard = fa
|
|||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 规范化并校验相对路径:允许子目录,但禁止通过 ".." 穿越到根外。
|
||||
* 用于插件存储,确保路径不逃出指定根目录。
|
||||
* @returns 规范化后的相对路径(使用 /),若路径非法则返回 null
|
||||
*/
|
||||
export const normalizeStoragePath = (storageName: string): string | null => {
|
||||
const normalized = storageName.replace(/\\/g, "/");
|
||||
const parts = normalized.split("/").filter(Boolean);
|
||||
const resolved: string[] = [];
|
||||
for (const part of parts) {
|
||||
if (part === "..") {
|
||||
if (resolved.length > 0) {
|
||||
resolved.pop();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else if (part !== ".") {
|
||||
resolved.push(part);
|
||||
}
|
||||
}
|
||||
return resolved.length > 0 ? resolved.join("/") : null;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue