Skip to content

Commit 5f5819d

Browse files
author
mrmlnc
committed
fix: scan full pattern when tokens are requested
The `tokens` option implicitly enables `parts`, but did not enable full-pattern scanning. This caused scanning to stop at the first glob and merge the remaining path segments into the final token. Include `tokens` in `scanToEnd` and add regression coverage for #62.
1 parent 4f41a8e commit 5f5819d

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

lib/scan.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const scan = (input, options) => {
5050
const opts = options || {};
5151

5252
const length = input.length - 1;
53-
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
53+
const scanToEnd = opts.parts === true || opts.tokens === true || opts.scanToEnd === true;
5454
const slashes = [];
5555
const tokens = [];
5656
const parts = [];

test/api.scan.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ describe('picomatch', () => {
375375
assertParts('foo/[0-9]/[0-9]', ['foo', '[0-9]', '[0-9]']);
376376
assertParts('foo[0-9]/bar[0-9]', ['foo[0-9]', 'bar[0-9]']);
377377
});
378+
379+
it('issue #62: should enable parts when tokens are requested', () => {
380+
const state = scan('a/b/*/c', { tokens: true });
381+
assert.deepStrictEqual(state.parts, ['a', 'b', '*', 'c']);
382+
});
378383
});
379384

380385
describe('.base (glob2base test patterns)', () => {

0 commit comments

Comments
 (0)