fast-glob icon indicating copy to clipboard operation
fast-glob copied to clipboard

fast-glob doesn't match list segments correctly

Open AgentEnder opened this issue 2 years ago • 3 comments

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

  • See linked PR with test: #366

AgentEnder avatar Jun 16 '22 19:06 AgentEnder

@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 avatar Jun 16 '22 20:06 AgentEnder

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))$

AgentEnder avatar Jun 16 '22 20:06 AgentEnder

'**/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.

mrmlnc avatar Jul 16 '22 09:07 mrmlnc

@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 avatar Oct 12 '22 16:10 AgentEnder

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 avatar Dec 14 '22 14:12 AgentEnder

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.

AgentEnder avatar Dec 28 '22 03:12 AgentEnder

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

mrmlnc avatar May 14 '23 09:05 mrmlnc

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

AgentEnder avatar May 14 '23 23:05 AgentEnder