fix: masks starting with **/*/ where not applied correctly
Massimo Melina committed
Dec 30, 2023 at 13:03 UTC
e4595ab95b24ffc99bec034fadb54fc6278ff9c0
1 file changed
+7
-4
src/vfs.ts
+7
-4
@@ -307,7 +307,7 @@ export function masksCouldGivePermission(masks: Masks | undefined, perm: keyof V
307
308
export function parentMaskApplier(parent: VfsNode) {
309
const matchers = onlyTruthy(Object.entries(parent.masks || {}).map(([k, { maskOnly, ...mods }]) => {
310
- k = k.startsWith('**/') ? k.slice(3) : !k.includes('/') ? k : ''
310
+ k = k.startsWith('**/') ? k.slice(3) : !k.includes('/') ? k : '' // ** globstar matches also zero subfolders, so this mask must be applied here too
311
return k && { mods, maskOnly, matcher: makeMatcher(k) }
312
}))
313
return (item: VfsNode, virtualBasename=getNodeName(item)) => {
@@ -327,10 +327,13 @@ function inheritMasks(item: VfsNode, parent: VfsNode, virtualBasename:string) {
327
const o: Masks = {}
328
for (const [k,v] of Object.entries(masks)) {
329
const neg = k[0] === '!' && k[1] !== '(' ? '!' : ''
330
- const withoutNeg = neg ? k.slice(1) : k
331
- if (withoutNeg.startsWith('**'))
330
+ let withoutNeg = neg ? k.slice(1) : k
331
+ if (withoutNeg.startsWith('**')) {
332
o[k] = v
333
- else if (withoutNeg.startsWith('*/'))
333
+ if (withoutNeg[2] === '/')
334
+ withoutNeg = withoutNeg.slice(3) // this mask will apply also at the current level
335
+ }
336
+ if (withoutNeg.startsWith('*/'))
337
o[neg + withoutNeg.slice(2)] = v
338
else if (withoutNeg.startsWith(virtualBasename + '/'))
339
o[neg + withoutNeg.slice(virtualBasename.length + 1)] = v