diff --git a/minimatch.js b/minimatch.js index 7bf2b3cf..cd61ecfd 100644 --- a/minimatch.js +++ b/minimatch.js @@ -427,7 +427,7 @@ class Minimatch { if (pattern === '') return '' let re = '' - let hasMagic = !!options.nocase + let hasMagic = false let escaping = false // ? => one single character const patternListStack = [] @@ -750,6 +750,11 @@ class Minimatch { return [re, hasMagic] } + // if it's nocase, and the lcase/uppercase don't match, it's magic + if (options.nocase && !hasMagic) { + hasMagic = pattern.toUpperCase() !== pattern.toLowerCase() + } + // skip the regexp for non-magical patterns // unescape anything in it, though, so that it'll be // an exact match against a file etc. diff --git a/tap-snapshots/test/basic.js.test.cjs b/tap-snapshots/test/basic.js.test.cjs index 11571184..bd2a6a71 100644 --- a/tap-snapshots/test/basic.js.test.cjs +++ b/tap-snapshots/test/basic.js.test.cjs @@ -162,7 +162,7 @@ exports[`test/basic.js TAP basic tests > makeRe X* 2`] = ` ` exports[`test/basic.js TAP basic tests > makeRe XYZ 1`] = ` -/^(?:(?=.)XYZ)$/i +/^(?:XYZ)$/i ` exports[`test/basic.js TAP basic tests > makeRe [ 1`] = ` diff --git a/test/nocase-magic.js b/test/nocase-magic.js new file mode 100644 index 00000000..d9dab906 --- /dev/null +++ b/test/nocase-magic.js @@ -0,0 +1,13 @@ +const t = require('tap') +const { Minimatch } = require('../') + +const nomagic = '../1/2/3' +const yesmagic = '../x' + +t.same(new Minimatch(nomagic, { nocase: true }).set, [ + [ '..', '1', '2', '3'] +]) + +t.same(new Minimatch(yesmagic, { nocase: true }).set, [ + ['..', /^x$/i] +])