isaacs / minimatch

a glob matcher in javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nesting !() extglob inside of first part of ?() extglob fails

isaacs opened this issue · comments

isaacs/node-glob#516

> new Minimatch('?(x-!(y)|z)').match('x-a')
false

> new Minimatch('?(x-!(y)|z)').set
[
  [
    /^(?=.)(?:(?!\.)x\-(?:(?!(?:y)|(?!\.z)?)[^/]*?)|(?!\.)z)?$/ {
      _glob: '?(x-!(y)|z)',
      _src: '(?=.)(?:(?!\\.)x\\-(?:(?!(?:y)|(?!\\.z)?)[^/]*?)|(?!\\.)z)?'
    }
  ]
]

Curiously, this works, though:

> new Minimatch('?(x-!(y)|z)b').match('x-ab')
true

It's only failing when the containing extglob goes to the end of the path part.

But not if the match for the !() also matches the rest of the pattern after the ?():

> m = new Minimatch('?(x-!(y)|z)b').match('x-bb')
false

It's time for a proper recursive descent parser.

I've got this almost working, and the new approach is a bit faster in some cases actually, since it can usually generate more efficient regular expressions. But it's a big refactor of the parser, so it may end up being a major version bump.