picomatch icon indicating copy to clipboard operation
picomatch copied to clipboard

Can't match **.internal-test.js

Open jakobrosenberg opened this issue 2 years ago • 3 comments

I would expect the below to be true

const isMatch = picomatch('**.internal-test.js')
isMatch('my-tests/some-spec.internal-test.js') // false

However this works

const regex = picomatch.toRegex(picomatch.parse('**.internal-test.js').output)
regex.test('my-tests/some-spec.internal-test.js') // true

jakobrosenberg avatar Nov 20 '21 07:11 jakobrosenberg

Fixed with by changing glob to **/*.internal-test.js

jakobrosenberg avatar Nov 20 '21 07:11 jakobrosenberg

I noticed this inconsistency. Not sure if this is by design or a bug. To err on the side of caution, I'll reopen the issue.

import picomatch from "picomatch";

const isMatch1 = picomatch('**/*.dash-thing.js')
const isMatch2 = picomatch('**/*.thing.js')
const isMatch3 = picomatch('**.dash-thing.js')
const isMatch4 = picomatch('**.thing.js')

console.log(isMatch1('somepath/test.dash-thing.js')) // true
console.log(isMatch2('somepath/test.thing.js'))      // true
console.log(isMatch3('somepath/test.dash-thing.js')) // false
console.log(isMatch4('somepath/test.thing.js'))      // true

jakobrosenberg avatar Nov 20 '21 08:11 jakobrosenberg

Good catch. '**.thing.js' should not match, so that is a bug since ** should be treated as a single star when it's not the only thing in a path segment (according to bash).

However, the correct way to do what you want is one of the following:

const isMatch1 = picomatch('*/*.thing.js')
const isMatch2 = picomatch('**/*.thing.js')

console.log(isMatch1('somepath/test.thing.js'))      // true
console.log(isMatch2('somepath/test.thing.js'))      // true

thanks for the issue!

jonschlinkert avatar Nov 21 '21 06:11 jonschlinkert