Skip to content

Commit

Permalink
fix: disable fastpaths mode for parse method
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmlnc committed Dec 23, 2019
1 parent 44c925c commit 5b8d33f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/picomatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str
* @api public
*/

picomatch.parse = (glob, options) => parse(glob, options);
picomatch.parse = (glob, options) => parse(glob, {
...options,
fastpaths: false
});

/**
* Scan a glob pattern to separate the pattern into segments.
Expand Down
40 changes: 40 additions & 0 deletions test/api.picomatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ const assert = require('assert');
const picomatch = require('..');
const { isMatch } = picomatch;

const assertTokens = (actual, expected) => {
const keyValuePairs = actual.map((token) => [token.type, token.value]);

assert.deepStrictEqual(keyValuePairs, expected);
};

describe('picomatch', () => {
describe('validation', () => {
it('should throw an error when invalid arguments are given', () => {
Expand Down Expand Up @@ -307,4 +313,38 @@ describe('picomatch', () => {
assert(isMatch('a/b/c/.xyz.md', 'a/b/c/.*.md', { dot: true }));
});
});

describe('.parse', () => {
describe('tokens', () => {
it('should return result for pattern that matched by fastpath', () => {
const { tokens } = picomatch.parse('a*.txt');

const expected = [
['bos', ''],
['text', 'a'],
['star', '*'],
['text', '.txt']
];

assertTokens(tokens, expected);
});

it('should return result for pattern', () => {
const { tokens } = picomatch.parse('{a,b}*');

const expected = [
['bos', ''],
['brace', '{'],
['text', 'a'],
['comma', ','],
['text', 'b'],
['brace', '}'],
['star', '*'],
['maybe_slash', '']
];

assertTokens(tokens, expected);
});
});
});
});

0 comments on commit 5b8d33f

Please sign in to comment.