micromatch / braces

Faster brace expansion for node.js. Besides being faster, braces is not subject to DoS attacks like minimatch, is more accurate, and has more complete support for Bash 4.3.
https://github.com/jonschlinkert
MIT License
207 stars 47 forks source link

nested bracket mistake #2

Closed isaacs closed 9 years ago

isaacs commented 9 years ago
$ node -p 'require("./")("{a,b}{{a,b},a,b}")'
[ 'aa', 'ab', 'ba', 'bb' ]

$ echo {a,b}{{a,b},a,b}
aa ab aa ab ba bb ba bb
jonschlinkert commented 9 years ago

were you using the minimatch branch?

I get [ 'aa', 'ab', 'ba', 'bb' ]

isaacs commented 9 years ago

Yeah, that's incorrect. I think the avoidance of duplicates is the problem here, and probably a whole new strategy is needed.

Looking at the bash source code (braces.c, which is a bit of a convoluted mess with gotos and breaks out of a do/while and so on, but whatever) it looks like the process is something like this:

$ echo {a,b}{{a,b},a,b}
aa ab aa ab ba bb ba bb

$ echo a{{a,b},a,b} b{{a,b},a,b}
aa ab aa ab ba bb ba bb

$ echo a{a,b} aa ab b{a,b} ba bb
aa ab aa ab ba bb ba bb

$ echo aa ab aa ab ba bb ba bb
aa ab aa ab ba bb ba bb

That is:

  1. Find the first matched { character, and then get the bit before and after the braced set, and the braced set.
  2. Expand the braced set, appending all set pieces into the prefix and postfix.
  3. Repeat until no more matched { remain.

If I get a chance between family and holiday travel this week, I'll take a crack at a poc.

jonschlinkert commented 9 years ago

thanks for clarifying. yeah obviously I was trying to eliminate dupes, from my frame of reference that made sense. I'll try to come up with ideas too. and no hurry on my end! enjoy the holiday!

jonschlinkert commented 9 years ago

btw, thanks for taking the time to look at the code and review. I really appreciate it. I'm always looking for opportunities to learn.

isaacs commented 9 years ago

Happy to help! Making node-glob 100% identical to Bash has become a mildly obsessive hobby for me lately. It's more entertaining than TV ;)

jonschlinkert commented 9 years ago

has become a mildly obsessive hobby

Lol, I know exactly what you mean. we do the same with commonmark on remarkable. as a "higher power", deferring to commonmark makes syntax decisions super easy.

On a related topic (bash coverage), I thought of something related earlier that seems really interesting and wanted to run it by you. Any interest in collaborating on a minimatch lib with a reduced feature set? e.g. micromatch? just for fun, no expectations or whatever.

you would know this better than me, but I would guess that the majortity of minimatch users use a handful of the features. So my thinking is that micromatch could fill a niche to focus specifically on speed, and only offer support for a specific set of globbing/brace expansion features. seems like this would make decisions in both libs easier regarding features/support. just a thought

jonschlinkert commented 9 years ago

closing since this is the behavior we want in braces, e.g. node.js versus bash.