Skip to content

Commit 71b78a2

Browse files
committed
fix partial matching of globstar patterns
Fix: #284 Backport of 3a0d83b to v9
1 parent 2de496f commit 71b78a2

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,11 @@ export class Minimatch {
835835
const firstgs = pattern.indexOf(GLOBSTAR, patternIndex)
836836
const lastgs = pattern.lastIndexOf(GLOBSTAR)
837837

838-
const [head, body, tail] = [
838+
const [head, body, tail] = partial ? [
839+
pattern.slice(patternIndex, firstgs),
840+
pattern.slice(firstgs + 1),
841+
[],
842+
] : [
839843
pattern.slice(patternIndex, firstgs),
840844
pattern.slice(firstgs + 1, lastgs),
841845
pattern.slice(lastgs + 1),
@@ -878,7 +882,7 @@ export class Minimatch {
878882
return false
879883
}
880884
}
881-
return sawSome
885+
return partial || sawSome
882886
}
883887

884888
const bodySegments: [ParseReturn[], number][] = [[[], 0]]
@@ -952,7 +956,7 @@ export class Minimatch {
952956
}
953957
fileIndex++
954958
}
955-
return null
959+
return partial || null
956960
}
957961

958962
#matchOne(

test/partial.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import t from 'tap'
22
import { minimatch as mm } from '../dist/esm/index.js'
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)