Skip to content

Commit

Permalink
fix: mask "!" operator wasn't working
Browse files Browse the repository at this point in the history
  • Loading branch information
rejetto committed Apr 10, 2023
1 parent f385d68 commit cf17a5d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ export function makeNetMatcher(mask: string, emptyMaskReturns=false) {
}

export function makeMatcher(mask: string, emptyMaskReturns=false) {
return mask ? matcher('(' + mask + ')') // adding () will allow us to use the pipe at root level
return mask ? matcher(mask.replace(/^(!)?/, '$1(') + ')') // adding () will allow us to use the pipe at root level
: () => emptyMaskReturns
}

export function matches(s: string, mask: string, emptyMaskReturns=false) {
return makeMatcher('(' + mask + ')', emptyMaskReturns)(s) // adding () will allow us to use the pipe at root level
return makeMatcher(mask, emptyMaskReturns)(s) // adding () will allow us to use the pipe at root level
}

export function same(a: any, b: any) {
Expand Down
14 changes: 7 additions & 7 deletions src/vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ function inheritMasks(item: VfsNode, parent: VfsNode, virtualBasename:string) {
const { masks } = parent
if (!masks) return
const o: Masks = {}
for (const [k,v] of Object.entries(masks))
if (k.startsWith('**')) {
for (const [k,v] of Object.entries(masks)) {
const neg = k[0] === '!' && k[1] !== '(' ? '!' : ''
const withoutNeg = neg ? k.slice(1) : k
if (withoutNeg.startsWith('**'))
o[k] = v
if (k[3] === '/' )
o[k.slice(3)] = v
}
else if (k.startsWith(virtualBasename+'/'))
o[k.slice(virtualBasename.length+1)] = v
else if (withoutNeg.startsWith(virtualBasename + '/'))
o[neg + withoutNeg.slice(virtualBasename.length + 1)] = v
}
if (Object.keys(o).length)
item.masks = _.defaults(item.masks, o)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ vfs:
mime:
"*": auto
masks:
tests/page/*.html:
"!tests/page/*.png":
mime: text/plain
protectFromAbove/child/*.txt:
can_read: false
Expand Down

0 comments on commit cf17a5d

Please sign in to comment.