match urls ignoring case on Windows
Massimo Melina committed
Mar 18, 2022 at 10:54 UTC
46fd5762a0cb46eceb26528915078f1fe06cf139
2 files changed
+9
-1
server/src/misc.ts
+4
@@ -190,3 +190,7 @@ export function objRenameKey(o: Dict | undefined, from: string, to: string) {
190
export function typedKeys<T>(o: T) {
191
return Object.keys(o) as (keyof T)[]
192
}
193
+
194
+export function with_<T,RT>(par:T, cb: (par:T) => RT) {
195
+ return cb(par)
196
+}
server/src/vfs.ts
+5
-1
@@ -11,6 +11,7 @@ import { setConfig, subscribeConfig } from './config'
11
import { FORBIDDEN, IS_WINDOWS } from './const'
12
import events from './events'
13
import { getCurrentUsernameExpanded } from './perm'
14
+import { with_ } from './misc'
15
16
const WHO_ANYONE = true
17
const WHO_NO_ONE = false
@@ -85,7 +86,10 @@ export async function urlToNode(url: string, ctx?: Koa.Context, parent: VfsNode=
86
inheritMasks(ret, parent, name)
87
applyMasks(ret, parent, name)
88
// does the tree node have a child that goes by this name?
88
- const child = parent.children?.find(x => getNodeName(x) === name)
89
+ const sameName = !IS_WINDOWS ? (x:string) => x === name // easy
90
+ : with_(name.toLowerCase(), lc =>
91
+ (x: string) => x.toLowerCase() === lc)
92
+ const child = parent.children?.find(x => sameName(getNodeName(x)))
93
if (child) // yes
94
return urlToNode(rest, ctx, Object.assign(ret, child, { original: child }))
95
// not in the tree, we can see consider continuing on the disk