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

extglob bug: '*(?)' pattern wrongly excludes files with extensions #211

Closed
ds300 opened this issue Jun 4, 2023 · 2 comments
Closed

extglob bug: '*(?)' pattern wrongly excludes files with extensions #211

ds300 opened this issue Jun 4, 2023 · 2 comments

Comments

@ds300
Copy link

ds300 commented Jun 4, 2023

I'm doing some generative tests using minimatch as a gold standard, and ran into one niche issue that seems to be a bug with minimatch:

> require('minimatch').makeRe('/*(?)').test('/ok')
true ✅
> require('minimatch').makeRe('/*(?)').test('/ok.txt')
false ❌ I would expect this to also be true

I'm interpreting *(?) in this situation as

0 or more occurrences of any character except slash, failing if the first character is a dot

The compiled regex is

/^\/(?:(?!\.)[^/])*$/

but i think that star should be nudged over into the parens

/^\/(?:(?!\.)[^/]*)$/
@isaacs
Copy link
Owner

isaacs commented Jun 16, 2023

Hm, yes, the generated regexp is noting that the ? is matching the first item in a path portion, and thus disallowing a dot. However, it needs to treat that as effectively (not a dot)(anything)* in repeated cases.

@isaacs
Copy link
Owner

isaacs commented Jun 16, 2023

Putting the * inside the paren would fix it in this specific case, but the paren in question corresponds to the ) in *(...|...), and the dot prevention needs to be attached to the sub-pattern, to support stuff like ?(*|.a) where one allows dots and another doesn't.

So the fix will be a little more complicated.

@isaacs isaacs closed this as completed in 37f6df6 Jun 23, 2023
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

2 participants