Skip to content

Commit b02ef18

Browse files
committed
fix partial matching of globstar patterns
Fix: #284 Backport of 3a0d83b to v5
1 parent e92ae29 commit b02ef18

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

minimatch.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ class Minimatch {
277277
}
278278

279279
const head = pattern.slice(patternIndex, firstgs)
280-
const body = pattern.slice(firstgs + 1, lastgs)
281-
const tail = pattern.slice(lastgs + 1)
280+
const body = partial ? pattern.slice(firstgs + 1) : pattern.slice(firstgs + 1, lastgs)
281+
const tail = partial ? [] : pattern.slice(lastgs + 1)
282282

283283
// check the head
284284
if (head.length) {
@@ -321,7 +321,7 @@ class Minimatch {
321321
return false
322322
}
323323
}
324-
return sawSome
324+
return partial || sawSome
325325
}
326326

327327
// split body into segments at each GLOBSTAR
@@ -398,7 +398,7 @@ class Minimatch {
398398
}
399399
fileIndex++
400400
}
401-
return null
401+
return partial || null
402402
}
403403

404404
_matchOne (file, pattern, partial, fileIndex, patternIndex) {

test/partial.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
const t = require('tap')
22
const mm = require('../')
3+
34
t.equal(mm('/a/b', '/*/b/x/y/z', { partial: true }), true)
45
t.equal(mm('/a/b/c', '/*/b/x/y/z', { partial: true }), false)
56
t.equal(mm('/', 'x', { partial: true }), true)
67
const m = new mm.Minimatch('/*/b/x/y/z')
78
t.equal(m.match('/a/b', true), true)
9+
t.equal(mm('/b/c/d/a', '/**/a/b/c', { partial: true }), true)
10+
t.equal(mm('/b/c/d/a', '/**/a/b/c/**', { partial: true }), true)
11+
12+
t.equal(mm('a', 'a/**', { partial: true }), true)
13+
t.equal(mm('a', '**', { partial: true }), true)
14+
t.equal(mm('b/a', 'a/**', { partial: true }), false)
15+
t.equal(mm('/b/c/d/a', '/**/a/**/b/c/**', { partial: true }), true)
16+
t.equal(mm('/b/c/d/a', '/**/a/**', { partial: true }), true)

0 commit comments

Comments
 (0)