Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] globstar doesn't match paths that have no leading directories when used under a brace #115

Open
AgentEnder opened this issue Dec 28, 2022 · 0 comments

Comments

@AgentEnder
Copy link

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: mrmlnc/fast-glob#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant