Skip to content

Commit 9fab7bf

Browse files
authored
Merge pull request #181 from fdma/fix/globstar-adjacent-literal-issue-99
fix: treat `**` adjacent to a literal as a single star (#99)
2 parents 838c9d7 + 8f5ecc0 commit 9fab7bf

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

lib/parse.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,11 @@ parse.fastpaths = (input, options) => {
14081408
const match = /^(.*?)\.(\w+)$/.exec(str);
14091409
if (!match) return;
14101410

1411+
// A bare `**` here is adjacent to a literal extension in the same path
1412+
// segment (e.g. `**.js`), so it must act as a single star rather than a
1413+
// globstar. Bail out of the fast path and let the full parser handle it.
1414+
if (match[1] === '**') return;
1415+
14111416
const source = create(match[1]);
14121417
if (!source) return;
14131418

test/issue-related.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,16 @@ describe('issue-related tests', () => {
7272
assert(!isMatch('test/utils', 'test(/utils/**)', { strictSlashes: true }));
7373
assert(!isMatch('test/utils', 'test(/utils/**)/file'));
7474
});
75+
76+
it('should treat a leading `**` followed by a literal as a single star (picomatch/issues#99)', () => {
77+
// `**` only acts as a globstar when it is the sole content of a path segment.
78+
// When it is adjacent to other characters in the same segment (here `.thing.js`),
79+
// it must behave like a single star and not match across path separators.
80+
assert(!isMatch('somepath/test.thing.js', '**.thing.js'));
81+
assert(!isMatch('a/b/c.js', '**.js'));
82+
// these sibling cases already behaved correctly and must keep working
83+
assert(!isMatch('somepath/test.dash-thing.js', '**.dash-thing.js'));
84+
assert(isMatch('test.thing.js', '**.thing.js'));
85+
assert(isMatch('somepath/test.thing.js', '**/*.thing.js'));
86+
});
7587
});

0 commit comments

Comments
 (0)