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
220 stars 61 forks source link

Fails to expand Windows paths with brackets #16

Closed naturalethic closed 6 years ago

naturalethic commented 6 years ago
> const p2 = 'C:\\Users\\foo\\Workspace\\project\\routes\\[locale]'
> braces.expand(p2)
Error: no parsers registered for: "]"
    at parse (C:\Users\foo\Workspace\project\node_modules\snapdragon\lib\parser.js:475:15)
jonschlinkert commented 6 years ago

This is correct, you escaped the first brace, \\[ so the second one is a parsing error. Backticks are used for escaping in glob patterns. All path separators must be forward slashes. This isn't our rule, it's the rule for all globbing libraries.

naturalethic commented 6 years ago

Those aren't escaped brackets, they're escaped backslashes for a windows path. Keep in mind that p2 resolves internally to the string 'C:\Users\foo\Workspace\project\routes\[locale]', with no escapes. Those are literal backslashes, not escape sequences.

naturalethic commented 6 years ago

This isn't our rule, it's the rule for all globbing libraries.

If that is true, perhaps this bug belongs to chokidar, we'll see what they say on their ticket.

jonschlinkert commented 6 years ago

To be clear, chokidar is broken on Windows due to this libraries inability to recognize this condition.

To be clear, \\[foo] is an invalid bracket expression. This topic has been exhaustively discussed on many issues on several projects. If chokidar is creating the glob pattern, then that is a bug in chokidar, since glob patterns should only use backslashes for escaping a value. Given that \\ in a string is converted to \ in a regex, it is actually escaping [, not the backslash. I would be happy to discuss and help with creating a solution on chokidar. But it is not a bug in this library.

jonschlinkert commented 6 years ago

If that is true, perhaps this bug belongs to chokidar, we'll see what they say on their ticket.

I'd be happy to help there.

naturalethic commented 6 years ago

Yep, ok sorry, i had deleted that line in my comment, I'm not fully awake yet.

jonschlinkert commented 6 years ago

Yep, ok sorry, i had deleted that line in my comment, I'm not fully awake yet.

no that's ok, I didn't mean to sound harsh. it happens

sorentycho commented 5 years ago

Definitely looks like this is a chokidar bug: https://github.com/paulmillr/chokidar/issues/699#issuecomment-437293197