Skip to content

Commit d67fa3f

Browse files
committed
do not create empty patterns via ..
1 parent a26fe30 commit d67fa3f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ export class Minimatch {
397397
}
398398
} while (swapped)
399399
}
400-
this.globParts = rawGlobParts.map(parts =>
401-
parts.reduce((set: string[], part) => {
400+
this.globParts = rawGlobParts.map(parts => {
401+
parts = parts.reduce((set: string[], part) => {
402402
const prev = set[set.length - 1]
403403
if (part === '**' && prev === '**') {
404404
return set
@@ -412,7 +412,8 @@ export class Minimatch {
412412
set.push(part)
413413
return set
414414
}, [])
415-
)
415+
return parts.length === 0 ? [''] : parts
416+
})
416417
}
417418

418419
this.debug(this.pattern, this.globParts)

test/basic.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,9 @@ t.test('globstar re matches zero or more path portions', t => {
221221
}
222222
t.end()
223223
})
224+
225+
t.test('do not create empty pattern via ..', t =>{
226+
const m = new mm.Minimatch('*/..')
227+
t.same(m.globParts, [['']])
228+
t.end()
229+
})

0 commit comments

Comments
 (0)