micromatch / micromatch/picomatch
[bug] globstar doesn't match paths that have no leading directories when used under a brace
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.3k
- Forks
- 135
- Avg merge
- 23h 38m
- Merged PRs (30d)
- 7
Description
Hey @jonschlinkert!
Thanks for the great parser and matcher! I'd love to help contribute the fix for this, but may need some pointers as the parsing logic here seems pretty complex. For some history behind the issue, feel free to check out the initial report on fast-glob: https://github.com/mrmlnc/fast-glob/issues/365
Creating a file called test.js in this repo with the following contents illustrates the problem pretty easily:
const picomatch = require('./index.js');
const target = '**/foo.md';
const other = 'bar.md';
const pattern = `{${target},${other}}`;
const combinedMatcher = picomatch(pattern);
const targetMatcher = picomatch(target);
for (const path of ['foo.md']) {
console.log(`targetMatcher(${path}): ` + targetMatcher(path));
console.log(`combinedMatcher(${path}): ` + combinedMatcher(path));
}
console.log('targetted regex: ' + picomatch.makeRe(target));
console.log('combined regex: ' + picomatch.makeRe(pattern));
The terminal output looks something like this:
> node test.js
targetMatcher(foo.md): true
combinedMatcher(foo.md): false
targetted regex: /^(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)foo\.md)$/
combined regex: /^(?:((?:(?:(?!(?:^|\/)\.).)*?)\/foo\.md|bar\.md))$/
In short, the targetted pattern isn't matched once it is part of a brace group. Looking at the combined regex, it appears there is a / literal inserted before the 'foo' literal that isn't present in the targetted regex, likely causing the issue.
Let me know if there is anything I can do to help get this fixed, as its presenting as an issue within Nx and we'd love to be able to mitigate.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in index.js and reproduce the issue with the test.js example from the report. Compare the matcher and generated regex for '/foo.md' with the brace pattern '{/foo.md,bar.md}', then trace the parsing path that inserts the extra slash. Done means 'foo.md' matches the combined pattern without regressing the existing target pattern.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100