fix: files with "\" in the name couldn't be interacted with #688
Massimo Melina committed
Aug 17, 2024 at 13:14 UTC
d1d59fdb32be2b46788918896ba546a72173ca63
2 files changed
+2
-2
src/util-files.ts
+1
-1
@@ -148,7 +148,7 @@ export function createFileWithPath(path: string, options?: Parameters<typeof cre
148
}
149
150
export function isValidFileName(name: string) {
151
- return !/[/*?<>|\\]/.test(name) && !dirTraversal(name)
151
+ return !(IS_WINDOWS ? /[/:"*?<>|\\]/ : /\//).test(name) && !dirTraversal(name)
152
}
153
154
export function exists(path: string) {
src/vfs.ts
+1
-1
@@ -137,7 +137,6 @@ export async function urlToNode(url: string, ctx?: Koa.Context, parent: VfsNode=
137
}
138
139
export async function getNodeByName(name: string, parent: VfsNode) {
140
- if (!isValidFileName(name)) return
140
// does the tree node have a child that goes by this name, otherwise attempt disk
141
const child = parent.children?.find(isSameFilenameAs(name)) || childFromDisk()
142
return child && applyParentToChild(child, parent, name)
@@ -154,6 +153,7 @@ export async function getNodeByName(name: string, parent: VfsNode) {
153
}
154
ret.rename = renameUnderPath(parent.rename, name)
155
}
156
+ if (!isValidFileName(onDisk)) return
157
ret.source = join(parent.source, onDisk)
158
ret.original = undefined // overwrite in applyParentToChild, so we know this is not part of the vfs
159
return ret