diff --git a/lib/picomatch.js b/lib/picomatch.js index fbb8b1c..448d354 100644 --- a/lib/picomatch.js +++ b/lib/picomatch.js @@ -157,9 +157,9 @@ picomatch.test = (input, regex, options, { glob, posix } = {}) => { * @api public */ -picomatch.matchBase = (input, glob, options) => { +picomatch.matchBase = (input, glob, options, posix = options && options.windows) => { const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options); - return regex.test(utils.basename(input)); + return regex.test(utils.basename(input, { windows: posix })); }; /** diff --git a/test/options.js b/test/options.js index 8993d18..5d0f98a 100644 --- a/test/options.js +++ b/test/options.js @@ -2,7 +2,7 @@ const assert = require('assert'); const match = require('./support/match'); -const { isMatch } = require('..'); +const { isMatch, matchBase } = require('..'); describe('options', () => { describe('options.matchBase', () => { @@ -15,6 +15,19 @@ describe('options', () => { assert.deepStrictEqual(match(['x/y/acb', 'acb/', 'acb/d/e', 'x/y/acb/d'], 'a?b', { matchBase: true, windows: true }), ['x/y/acb', 'acb/']); }); + it('should match the basename of backslash-separated paths when `options.windows` is true', () => { + assert(isMatch('foo\\bar.js', '*.js', { matchBase: true, windows: true })); + assert(isMatch('a\\b\\c\\d.md', '*.md', { matchBase: true, windows: true })); + assert(isMatch('a\\b\\c\\foo.md', '*.md', { matchBase: true, windows: true })); + assert(isMatch('x\\y\\acb', 'a?b', { matchBase: true, windows: true })); + assert(!isMatch('a\\b\\c\\d.md', '*.js', { matchBase: true, windows: true })); + }); + + it('should pass the `windows` option through `matchBase`', () => { + assert(matchBase('foo\\bar.js', '*.js', { windows: true })); + assert(matchBase('a\\b\\c\\d.md', '*.md', { windows: true })); + }); + it('should work with negation patterns', () => { assert(isMatch('./x/y.js', '*.js', { matchBase: true, windows: true })); assert(!isMatch('./x/y.js', '!*.js', { matchBase: true, windows: true }));