-
-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Patterns with escaped characters are incorrectly handled on Windows #212
Comments
Related: isaacs/minimatch#64 |
@isaacs This inconsistency between node-glob and minimatch on Windows is quite annoying... Escaping seems impossible in minimatch currently. People have submitted issues about it for some time, and there's a PR that seems eminently reasonable. Although having said that, I personally would probably prefer a major bump in minimatch adopting the same attitude as node-glob (forward slashes as path separators, backslashes as escape char, on all platforms). Anyway, this has been going on for a while now. I don't mean to sound impatient, but is there anything that can be done to move this forward? Or do you not agree this is a problem? |
This has been handled in both minimatch and glob now. Patterns must use |
Problem
The
node-glob
README states (under the Windows heading):However
minimatch
s implementation includes the following:On Windows (where
path.sep
is\
), this code means all escape characters are treated as path separators. Therefore sinceminimatch
does not treat\
as an escape character on Windows, then neither doesnode-glob
, despite what its REAMDE says.The impact is that on Windows platforms, escape characters in glob patterns will not work as intended.
This is an issue for cross-platform projects using this
node-glob
for globbing support.Example
Suppose I want to match javascript files whose names start with
[
and end with]
.A glob pattern for this, which requires escape characters, might be as follows:
\[*\].js
On Linux,
minimatch
converts the above pattern into the following Regex:/^(?:(?=.)\[[^/]*?\]\.js)$/
On Windows, the regex created by
minimatch
is:/^(?:\/(?=.)\[(?!\.)(?=.)[^/]*?\/\]\.js)$/
This latter regex does not match the specified glob pattern.
Solutions?
Arguably this is a
minimatch
issue, butminimatch
's README makes no particular claims about Windows support or handling, whereasnode-glob
does make the above claim.Possible solution in
node-glob
(leavingminimatch
unaffected):node-glob
README to state that escaped characters are not supported on Windows.Possible solution in
minimatch
(leavingnode-glob
unaffected):minimatch
README to require the same thingnode-glob
requires on Windows (ie: 'You must use forward-slashes only in glob expressions. Back-slashes will always be interpreted as escape characters, not path separators.')minimatch
code (snippet shown above) that turns\
s into/
on Windows.minimatch
option to explicitly specify the character to treat as the path separator.The text was updated successfully, but these errors were encountered: