glob icon indicating copy to clipboard operation
glob copied to clipboard

Incorrect regex generated for patterns with **

Open Crell opened this issue 1 year ago • 1 comments

I'm trying to filter some paths, where I want to use **. Unfortunately, the regex that's getting computed internal to Glob::filter() seems to be incorrect.

For example, the pattern /** compiles to ~^/[^/]*[^/]*$~. That will match /, /foo, /bar, but not /foo/bar. I believe it should be matching /foo/bar.

Similarly, the pattern /foo/** compiles to ~^/foo/[^/]*[^/]*$~. That will match /foo, /foo/bar, but not /foo/bar/baz.

So either there is a bug in the regex compiler in handling **, or I'm not understanding ** properly. I suppose either is possible. If there is some other way I should be doing this, please advise. (In practice I think I only need prefix-matching, but was trying to use a full glob for it for flexibility.)

Crell avatar Aug 10 '24 14:08 Crell

Docs state /**/`` matches zero or more directory names: don't have any more context than that myself either :|

I see that the tests aren't matching descendants: https://github.com/webmozarts/glob/blob/6712c9c4a8b0f6f629303bd1b26b9f88339d901e/tests/GlobTest.php#L93-L122

Ocramius avatar Aug 10 '24 15:08 Ocramius