fix: files with "\" in the name couldn't be interacted with #688

Massimo Melina committed Aug 17, 2024 at 13:14 UTC d67653fced89e598389b5de89c5cc3b3feebe6eb
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
@@ -139,7 +139,6 @@ export async function urlToNode(url: string, ctx?: Koa.Context, parent: VfsNode=
139 }
140
141 export async function getNodeByName(name: string, parent: VfsNode) {
142 - if (!isValidFileName(name)) return
142 // does the tree node have a child that goes by this name, otherwise attempt disk
143 const child = parent.children?.find(isSameFilenameAs(name)) || childFromDisk()
144 return child && applyParentToChild(child, parent, name)
@@ -156,6 +155,7 @@ export async function getNodeByName(name: string, parent: VfsNode) {
155 }
156 ret.rename = renameUnderPath(parent.rename, name)
157 }
158 + if (!isValidFileName(onDisk)) return
159 ret.source = join(parent.source, onDisk)
160 ret.original = undefined // overwrite in applyParentToChild, so we know this is not part of the vfs
161 return ret