fix: masks starting with **/*/ where not applied correctly

Massimo Melina committed Dec 30, 2023 at 13:03 UTC 74a1c65cd9d8349e579196f0d760525630134760
1 file changed +7 -4
src/vfs.ts
+7 -4
@@ -294,7 +294,7 @@ export function masksCouldGivePermission(masks: Masks | undefined, perm: keyof V
294
295 export function parentMaskApplier(parent: VfsNode) {
296 const matchers = onlyTruthy(Object.entries(parent.masks || {}).map(([k, { maskOnly, ...mods }]) => {
297 - k = k.startsWith('**/') ? k.slice(3) : !k.includes('/') ? k : ''
297 + k = k.startsWith('**/') ? k.slice(3) : !k.includes('/') ? k : '' // ** globstar matches also zero subfolders, so this mask must be applied here too
298 return k && { mods, maskOnly, matcher: makeMatcher(k) }
299 }))
300 return (item: VfsNode, virtualBasename=getNodeName(item)) => {
@@ -314,10 +314,13 @@ function inheritMasks(item: VfsNode, parent: VfsNode, virtualBasename:string) {
314 const o: Masks = {}
315 for (const [k,v] of Object.entries(masks)) {
316 const neg = k[0] === '!' && k[1] !== '(' ? '!' : ''
317 - const withoutNeg = neg ? k.slice(1) : k
318 - if (withoutNeg.startsWith('**'))
317 + let withoutNeg = neg ? k.slice(1) : k
318 + if (withoutNeg.startsWith('**')) {
319 o[k] = v
320 - else if (withoutNeg.startsWith('*/'))
320 + if (withoutNeg[2] === '/')
321 + withoutNeg = withoutNeg.slice(3) // this mask will apply also at the current level
322 + }
323 + if (withoutNeg.startsWith('*/'))
324 o[neg + withoutNeg.slice(2)] = v
325 else if (withoutNeg.startsWith(virtualBasename + '/'))
326 o[neg + withoutNeg.slice(virtualBasename.length + 1)] = v