diff --git a/src/index.ts b/src/index.ts index 89cbff06..8f4084c8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 @@ -412,7 +412,8 @@ export class Minimatch { set.push(part) return set }, []) - ) + return parts.length === 0 ? [''] : parts + }) } this.debug(this.pattern, this.globParts) diff --git a/test/basic.js b/test/basic.js index 6bc30ea4..5b3e9940 100644 --- a/test/basic.js +++ b/test/basic.js @@ -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() +})