Skip to content

Commit 5b8d33f

Browse files
committed
fix: disable fastpaths mode for parse method
1 parent 44c925c commit 5b8d33f

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/picomatch.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@ picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str
189189
* @api public
190190
*/
191191

192-
picomatch.parse = (glob, options) => parse(glob, options);
192+
picomatch.parse = (glob, options) => parse(glob, {
193+
...options,
194+
fastpaths: false
195+
});
193196

194197
/**
195198
* Scan a glob pattern to separate the pattern into segments.

test/api.picomatch.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ const assert = require('assert');
44
const picomatch = require('..');
55
const { isMatch } = picomatch;
66

7+
const assertTokens = (actual, expected) => {
8+
const keyValuePairs = actual.map((token) => [token.type, token.value]);
9+
10+
assert.deepStrictEqual(keyValuePairs, expected);
11+
};
12+
713
describe('picomatch', () => {
814
describe('validation', () => {
915
it('should throw an error when invalid arguments are given', () => {
@@ -307,4 +313,38 @@ describe('picomatch', () => {
307313
assert(isMatch('a/b/c/.xyz.md', 'a/b/c/.*.md', { dot: true }));
308314
});
309315
});
316+
317+
describe('.parse', () => {
318+
describe('tokens', () => {
319+
it('should return result for pattern that matched by fastpath', () => {
320+
const { tokens } = picomatch.parse('a*.txt');
321+
322+
const expected = [
323+
['bos', ''],
324+
['text', 'a'],
325+
['star', '*'],
326+
['text', '.txt']
327+
];
328+
329+
assertTokens(tokens, expected);
330+
});
331+
332+
it('should return result for pattern', () => {
333+
const { tokens } = picomatch.parse('{a,b}*');
334+
335+
const expected = [
336+
['bos', ''],
337+
['brace', '{'],
338+
['text', 'a'],
339+
['comma', ','],
340+
['text', 'b'],
341+
['brace', '}'],
342+
['star', '*'],
343+
['maybe_slash', '']
344+
];
345+
346+
assertTokens(tokens, expected);
347+
});
348+
});
349+
});
310350
});

0 commit comments

Comments
 (0)