Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/picomatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ picomatch.test = (input, regex, options, { glob, posix } = {}) => {
}

if (match === false || opts.capture === true) {
if (opts.matchBase === true || opts.basename === true) {
if (!glob.includes('/') && (opts.matchBase === true || opts.basename === true)) {
match = picomatch.matchBase(input, regex, options, posix);
} else {
match = regex.exec(output);
Expand Down
11 changes: 9 additions & 2 deletions test/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ describe('options', () => {
it('should work with negation patterns', () => {
assert(isMatch('./x/y.js', '*.js', { matchBase: true }));
assert(!isMatch('./x/y.js', '!*.js', { matchBase: true }));
assert(isMatch('./x/y.js', '**/*.js', { matchBase: true }));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not preserving the ./ is intentional—this is not a match according to minimatch.

assert(!isMatch('./x/y.js', '!**/*.js', { matchBase: true }));
});

it('should not affect patterns with slashes', () => {
assert(isMatch('x/y.js', 'x/**'));
assert(isMatch('x/y.js', 'x/**', { matchBase: true }));
assert(isMatch('x/y.js', '**/*.js'));
assert(isMatch('x/y.js', '**/*.js', { matchBase: true }));
assert(!isMatch('x/y.js', '!**/*.js'));
assert(!isMatch('x/y.js', '!**/*.js', { matchBase: true }));
});
});

Expand Down