Skip to content

Commit

Permalink
do not create empty patterns via ..
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Feb 13, 2023
1 parent a26fe30 commit d67fa3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ export class Minimatch {
}
} while (swapped)
}
this.globParts = rawGlobParts.map(parts =>
parts.reduce((set: string[], part) => {
this.globParts = rawGlobParts.map(parts => {
parts = parts.reduce((set: string[], part) => {
const prev = set[set.length - 1]
if (part === '**' && prev === '**') {
return set
Expand All @@ -412,7 +412,8 @@ export class Minimatch {
set.push(part)
return set
}, [])
)
return parts.length === 0 ? [''] : parts
})
}

this.debug(this.pattern, this.globParts)
Expand Down
6 changes: 6 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,9 @@ t.test('globstar re matches zero or more path portions', t => {
}
t.end()
})

t.test('do not create empty pattern via ..', t =>{
const m = new mm.Minimatch('*/..')
t.same(m.globParts, [['']])
t.end()
})

0 comments on commit d67fa3f

Please sign in to comment.