Skip to content

Commit 3a0d83b

Browse files
committed
fix partial matching of globstar patterns
Fix: #284
1 parent ea94840 commit 3a0d83b

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,11 @@ export class Minimatch {
951951
// split the pattern up into globstar-delimited sections
952952
// the tail has to be at the end, and the others just have
953953
// to be found in order from the head.
954-
const [head, body, tail] = [
954+
const [head, body, tail] = partial ? [
955+
pattern.slice(patternIndex, firstgs),
956+
pattern.slice(firstgs + 1),
957+
[],
958+
] : [
955959
pattern.slice(patternIndex, firstgs),
956960
pattern.slice(firstgs + 1, lastgs),
957961
pattern.slice(lastgs + 1),
@@ -1018,7 +1022,8 @@ export class Minimatch {
10181022
return false
10191023
}
10201024
}
1021-
return sawSome
1025+
// in partial mode, we just need to get past all file parts
1026+
return partial || sawSome
10221027
}
10231028

10241029
// now we know that there's one or more body sections, which can
@@ -1135,7 +1140,7 @@ export class Minimatch {
11351140
fileIndex++
11361141
}
11371142
// walked off. no point continuing
1138-
return null
1143+
return partial || null
11391144
}
11401145

11411146
#matchOne(

test/partial.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/partial.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import t from 'tap'
2+
import { minimatch as mm } from '../src/index.js'
3+
import type { MMRegExp } from '../src/index.js'
4+
5+
t.equal(mm('/a/b', '/*/b/x/y/z', { partial: true }), true)
6+
t.equal(mm('/a/b/c', '/*/b/x/y/z', { partial: true }), false)
7+
t.equal(mm('/', 'x', { partial: true }), true)
8+
const m = new mm.Minimatch('/*/b/x/y/z')
9+
t.equal(m.match('/a/b', true), true)
10+
t.equal(mm('/b/c/d/a', '/**/a/b/c', { partial: true }), true)
11+
t.equal(mm('/b/c/d/a', '/**/a/b/c/**', { partial: true }), true)
12+
13+
t.equal(mm('a', 'a/**', { partial: true }), true)
14+
t.equal(mm('a', '**', { partial: true }), true)
15+
t.equal(mm('b/a', 'a/**', { partial: true }), false)
16+
t.equal(mm('/b/c/d/a', '/**/a/**/b/c/**', { partial: true }), true)
17+
t.equal(mm('/b/c/d/a', '/**/a/**', { partial: true }), true)
18+
19+
t.equal(
20+
(mm.makeRe('/*/b/x/y/z', { partial: true }) as MMRegExp).test('/a/b'),
21+
true,
22+
)
23+
t.equal(
24+
(mm.makeRe('/*/b/x/y/z', { partial: true }) as MMRegExp).test('/a/b/c'),
25+
false,
26+
)
27+
t.equal((mm.makeRe('x', { partial: true }) as MMRegExp).test('/'), true)

0 commit comments

Comments
 (0)