fix: wrong interpretation of negative masks
Massimo Melina committed
Mar 30, 2025 at 11:22 UTC
074b52107e09d37852446c37eaef4bcf5570791c
2 files changed
+9
-13
src/vfs.ts
+7
-11
@@ -432,21 +432,17 @@ function inheritMasks(item: VfsNode, parent: VfsNode, virtualBasename=getNodeNam
432
const { masks } = parent
433
if (!masks) return
434
const o: Masks = {}
435
+ const prefix = virtualBasename + '/'
436
for (const [k,v] of Object.entries(masks)) {
436
- const neg = k[0] === '!' && k[1] !== '(' ? '!' : ''
437
- let withoutNeg = neg ? k.slice(1) : k
438
- if (withoutNeg.startsWith('**')) {
437
+ if (k.startsWith('**'))
438
o[k] = v
440
- if (withoutNeg[2] === '/')
441
- withoutNeg = withoutNeg.slice(3) // this mask will apply also at the current level
442
- }
443
- if (withoutNeg.startsWith('*/'))
444
- o[neg + withoutNeg.slice(2)] = v
445
- else if (withoutNeg.startsWith(virtualBasename + '/'))
446
- o[neg + withoutNeg.slice(virtualBasename.length + 1)] = v
439
+ else if (k.startsWith('*/'))
440
+ o[k.slice(2)] = v
441
+ else if (k.startsWith(prefix))
442
+ o[k.slice(prefix.length)] = v
443
}
444
if (Object.keys(o).length)
449
- item.masks = _.defaults(item.masks, o)
445
+ item.masks = Object.assign(o, item.masks) // don't change item.masks object as it is the same object of item.original
446
}
447
448
function renameUnderPath(rename:undefined | Record<string,string>, path: string) {
tests/config.yaml
+2
-2
@@ -4,7 +4,7 @@ allowed_referer: x.com
4
localhost_admin: false
5
vfs:
6
masks:
7
- "!tests/page/*.png":
7
+ tests/page/!*.png:
8
mime: text/plain
9
protectFromAbove/child/*.txt:
10
can_read: false
@@ -50,7 +50,7 @@ vfs:
50
- disabled_account
51
- source: tests
52
masks:
53
- "!**/*.png|files|":
53
+ "**/!*.png|files|":
54
can_see: false
55
- name: renameChild
56
children: