-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
!(*.js|*.json) does not match a.js.gz #10
Comments
Hi, thanks for creating an issue.
Please add a comparison of how bash handles these extglob patterns versus this library |
Hello, according to bash 4.4.12, it is a bug. shopt -s extglob
touch a.js a.js.gz a.json a.json.gz a.gz
ls !(*.js|*.json) # a.gz a.js.gz a.json.gz extglob will only match a.gz |
That seems like such incorrect behavior... |
which result? |
do the following instead: console.log(extglob.makeRe('*.!(js|json)').test('a.js.gz')); // true
console.log(extglob.makeRe('*.!(js|json)').test('a.json.gz')); // true
console.log(extglob.makeRe('*.!(js|json)').test('a.gz')); // true Even bash yields incorrect results sometimes when globs are nested inside negation globs. In javascript, we can't do negative lookbehinds in regular expressions, so it becomes very difficult or impossible to retroactively un-negate or un-match a substring. edit: also, I forgot to mention that technically bash in this case is performing a "contains" match, rather than an exact match. This library is stricter in that regard. You can also use your original patterns with console.log(extglob.makeRe('!(*.js|*.json)', {contains: true}).test('a.js.gz')); // true
console.log(extglob.makeRe('!(*.js|*.json)', {contains: true}).test('a.json.gz')); // true
console.log(extglob.makeRe('!(*.js|*.json)', {contains: true}).test('a.gz')); // true see https://github.com/micromatch/extglob#differences-from-bash |
btw, on a totally unrelated note, if you happen to notice this table being corrupted, that's a bug in github's markdown parser. |
Hi, thanks for the comments. Indeed it is hard without negative lookbehinds. console.log(extglob.makeRe('!(*.js|*.json)', {contains: true}).test('a.js')); // true, but I want it to be false
console.log(extglob.makeRe('!(*.js|*.json)', {contains: true}).test('a.js.gz')); // true
console.log(extglob.makeRe('!(*.js|*.json)', {contains: true}).test('a.json.gz')); // true
console.log(extglob.makeRe('!(*.js|*.json)', {contains: true}).test('a.gz')); // true I also tried to use the console.log(extglob.makeRe('*.!(js|json)').test('a')); // false I will look for a solution with 2 extglobs. |
I'm thinking this looks like a bug then. I try to stick to bash behavior, but sometimes bash is unable to handle certain patterns. In this case, it seems like bash is doing the right thing. edit: fwiw, here is what I think the results should be for all of the patterns you gave: console.log(extglob.makeRe('!(*.js|*.json)', {contains: true}).test('a.js')); // false
console.log(extglob.makeRe('!(*.js|*.json)', {contains: true}).test('a.js.gz')); // true
console.log(extglob.makeRe('!(*.js|*.json)', {contains: true}).test('a.json.gz')); // true
console.log(extglob.makeRe('!(*.js|*.json)', {contains: true}).test('a.gz')); // true
console.log(extglob.makeRe('*.!(js|json)').test('a')); // false I agree with your opinion on the first one, it seems like that should be The last one is correct because the pattern has |
Hello,
I am using extglob v2.0.2 and node v8.9.0.
As the title states, there is a case where a pattern does not match where I thought it would.
Should this not match or is it a bug?
The text was updated successfully, but these errors were encountered: