-
-
Notifications
You must be signed in to change notification settings - Fork 520
Description
Problem
The node-glob README states (under the Windows heading):
Back-slashes will always be interpreted as escape characters, not path separators
However minimatchs implementation includes the following:
// windows support: need to use /, not \
if (path.sep !== '/') {
pattern = pattern.split(path.sep).join('/')
}On Windows (where path.sep is \), this code means all escape characters are treated as path separators. Therefore since minimatch does not treat \ as an escape character on Windows, then neither does node-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, but minimatch's README makes no particular claims about Windows support or handling, whereas node-glob does make the above claim.
Possible solution in node-glob (leaving minimatch unaffected):
- amend the
node-globREADME to state that escaped characters are not supported on Windows.
Possible solution in minimatch (leaving node-glob unaffected):
- amend the
minimatchREADME to require the same thingnode-globrequires on Windows (ie: 'You must use forward-slashes only in glob expressions. Back-slashes will always be interpreted as escape characters, not path separators.') - remove the
minimatchcode (snippet shown above) that turns\s into/on Windows. - --or-- add a
minimatchoption to explicitly specify the character to treat as the path separator.