micromatch/extglob

questionable patterns

jonschlinkert opened this issue · 10 comments

While working on the refactor, these were the only patterns where Bash 4.3 disagreed with the results from this library. (fwiw minimatch fails 37 of the these tests).

I believe extglob is correct on most of these - this is only a few patterns with multiple examples for clarity (for example, IMHO !(foo)* should not match foo). I'd like some feedback on what the "verdict" should be.

edited 2016-10-17: most of these now agree. I realized that (in most of the listed cases) Bash is doing a "contains" match versus an "exact" match. Also, fwiw minimatch agrees with extglob on all cases except for the one minimatch fails on (which extglob and bash agree on). Unfortunately I've not been able to identify a specific reason that bash or minimatch disagree with this library on any cases - but it's clear that extglob is much more accurate than minimatch, and it appears that extglob is also more accurate than bash (it's known that bash still fails some edge cases).

String Pattern Bash Extglob Minimatch Agreed?
foo !(foo)* true true true
bar !(foo)* true true true
baz !(foo)* true true true
foobar !(foo)* true true true
foo *(!(foo)) true false true
moo.cow !(*.*).!(*.*) true true true
mad.moo.cow !(*.*).!(*.*) false true true X
foo.js.js *.!(js) true true true
foo.js.js *.!(js)* true false false X
foo.js.js *.!(js)+ false false false
foo.js.js *.!(js)*.!(js) false false false

Notes

One thing to consider is that whereas in bash, the extglob pattern might be the complete pattern, with this library the pattern is more likely to be a part of a larger glob pattern for testing file paths, etc.

cc @phated @doowb @tunnckoCore

moo.cow !(*.*).!(*.*)

I'm agree with Bash to be true, it make sense.

foo.js.js *.!(js)

and

foo.js.js *.!(js)*

I'm agree with Bash and seeing his the point to return true, but I'm curious what Bash says for *.!(js.)?

edit: maybe outer have precedence than inner here

foo *(!(foo))

hm... what about opposite: !(*(foo))?

In most cases I'm agree with extglob lib more than Bash.

hm... what about opposite

I'm running all of the Bash tests I was able to find - the table above lists the only patterns that extglob disagrees with bash on. Unfortunately the nuances of bash extglob don't seem to be consistent with regex - unless we can find a real specification, with sufficient detail to determine correct matching behavior, we'll just have to go with our best guess on some of these.

es128 commented

The patterns themselves are pretty bizarre and basically contradict themselves. Based on the chart I'd think extglob's behavior is more in line with what users would expect if they actually used these sorts of combinations, and I also think that when the pattern is odd/ambiguous it's better to "fail closed" and lean toward false when in doubt - so extglob still wins.

I suppose I could understand Bash's reasoning on some of these - particularly those with a trailing * (but at that point should a trailing * just trump absolutely anything else specified in the pattern?) - but a few I'm really struggling to understand how a match could be considered correct behavior.

Stellar work here @jonschlinkert

thanks for the feedback @es128!

I also think that when the pattern is odd/ambiguous it's better to "fail closed" and lean toward false when in doubt

yeah that's pretty similar to what I was thinking

I think I am pretty much agreement with everyone. extglob's behavior seems to be less surprising. Make sure to note the differences in the readme, of course.

Make sure to note the differences in the readme, of course

good call. I might have forgotten to do that thx

Yea, why not? Let's go with that agreement and if there so many users that are surprised in future, things can be done more strict and to stick more to Bash.

extglob's behavior is more in line with what users would expect if they actually used these sorts of combinations

Absolutely.

meaning you agree?

Yep, I don't have problems with most of them.

closing, I think this is resolved