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

fast-glob doesn't match list segments correctly #365

Closed
AgentEnder opened this issue Jun 16, 2022 · 8 comments
Closed

fast-glob doesn't match list segments correctly #365

AgentEnder opened this issue Jun 16, 2022 · 8 comments

Comments

@AgentEnder
Copy link
Contributor

AgentEnder commented Jun 16, 2022

Environment

  • OS Version: MacOS Big Sur (11.6.4)
  • Node.js Version: 17

Actual behavior

List-segments are matched in a way that is compatible with glob

Expected behavior

Some matches are not reported properly when using glob patterns containing quotes

Steps to reproduce

@AgentEnder
Copy link
Contributor Author

AgentEnder commented Jun 16, 2022

@mrmlnc When checking this out in a bit more detail, it seems like when matching list segments the globstar (**) can't evaluate to zero directories at the beginning of the pattern. This isn't standard, as it should be zero or more.

To be clear, this means you get equal results currently for:

{book.xml,library/**/a/book.md}

but failing results for:

{book.xml,**/library/*/book.md}

@AgentEnder
Copy link
Contributor Author

Followed up on this a bit more, the issue might be in micromatch or picomatch rather then the fast-glob package. It looks like for the above glob pattern, makeRe is returning this.

^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)\/library\/(?!\.)(?=.)[^/]*?\/book\.md))$

It should return something closer to this:

^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)library\/(?!\.)(?=.)[^/]*?\/book\.md))$

There is a pair of characters between literal library and the end of the group behind it (\/) that requires a slash at the beginning.

- ^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)\/library\/(?!\.)(?=.)[^/]*?\/book\.md))$
+ ^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)library\/(?!\.)(?=.)[^/]*?\/book\.md))$

@mrmlnc
Copy link
Owner

mrmlnc commented Jul 16, 2022

'**/library/*/book.md'

micromatch
{
  re: /^(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)library\/(?!\.)(?=.)[^/]*?\/book\.md)$/
}

fast-glob.utils.pattern.makeRe
{
  re: /^(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)library\/(?!\.)(?=.)[^/]*?\/book\.md)$/
}

---

'{book.xml,**/library/*/book.md}'

micromatch
{
  re: /^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)\/library\/(?!\.)(?=.)[^/]*?\/book\.md))$/
}

fast-glob.utils.pattern.makeRe
{
  re: /^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)\/library\/(?!\.)(?=.)[^/]*?\/book\.md))$/
}

Well, looks like this is really a problem in the micromatch package.

// {book.xml,**/library/*/book.md}
/^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)\/library\/(?!\.)(?=.)[^/]*?\/book\.md))$/
// **/library/*/book.md
/^(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)library\/(?!\.)(?=.)[^/]*?\/book\.md)$/

A little later I will create an issue in micromatch and try to find the reason for the current behavior.

@AgentEnder
Copy link
Contributor Author

@mrmlnc Is there an upstream issue link for this? I'm trying to keep an eye on this. If there is any way that I can help out, let me know. This issue currently presents in Nx when we combine glob patterns for finding plugin project files.

@AgentEnder
Copy link
Contributor Author

Hey @mrmlnc! Just checking in on this again. If someone can point me to the right spot to start making changes I'd be happy to investigate this a bit further myself.

@AgentEnder
Copy link
Contributor Author

I repro'd on the picomatch repo and opened an issue there, hoping to accelerate this one too. Let me know if there is anything else from my side that could help with this.

@mrmlnc
Copy link
Owner

mrmlnc commented May 14, 2023

Already fixed in the master by #395 in this package. Will be shipped with 3.3.0.

@mrmlnc mrmlnc closed this as completed May 14, 2023
@AgentEnder
Copy link
Contributor Author

Awesome! Thanks for the fix @mrmlnc! Happy maintainers month, hoping things are well for you.

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

No branches or pull requests

2 participants