Skip to content
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

Backslashes as path-separators #11

Closed
wants to merge 1 commit into from
Closed

Backslashes as path-separators #11

wants to merge 1 commit into from

Conversation

mde
Copy link

@mde mde commented Sep 24, 2012

Jake users on Windows are bumping into this.

Looks like slashes are already being normalized in Minimatch.prototype.match. I just used the same code, and duplicated the comment as well. Not really sure where the appropriate place would be to add a test for this, since it looks like from comments in basic.js that they likely don't run under Windows yet anyhow.

@isaacs
Copy link
Owner

isaacs commented Oct 4, 2012

Landed on b6f01f5. Thanks!

@isaacs isaacs closed this Oct 4, 2012
@isaacs
Copy link
Owner

isaacs commented Oct 4, 2012

Published as 0.2.7, if you're looking to update anything.

@kylealanhale
Copy link

I'm confused about this change. Glob's docs say to only use forward slashes for doing matches; this change appears to have broken doing matches on Windows.

@isaacs
Copy link
Owner

isaacs commented Oct 5, 2012

@kylealanhale What behavior are you seeing? Do you have a test that fails?

@kylealanhale
Copy link

So, it turns out that I had added a funky hack to work around the bug that was fixed by the pull request. I removed my hack, but my tests were still failing, so I've had to figure out another work around. Let me see if this makes sense to you.

I understand, and agree with using posix-style paths for patterns. However, I would think that the output of the glob would return paths in the format of the current environment. On posix systems, everything is fine, but for Windows I'm seeing all sorts of combinations. I haven't put together a test suite on this yet, but here's an illustration of what I'm seeing.

Let's say I have a folder that looks like this:

  • C:\
    • test\
      • deep\
        • test.txt
        • test.js
      • test.txt
      • test.js

I would expect the following commands to yield the given outputs:

> glob.sync('/test/*')
[ 'C:\\test\\deep',
  'C:\\test\\test.js',
  'C:\\test\\test.txt' ]
> glob.sync('/test/**')
[ 'C:\\test',
  'C:\\test\\deep',
  'C:\\test\\deep\\test.js',
  'C:\\test\\deep\\test.txt',
  'C:\\test\\test.js',
  'C:\\test\\test.txt' ]
> glob.sync('test/*', {cwd: 'C:\\'})
[ 'test\\deep',
  'test\\test.js',
  'test\\test.txt' ]
> glob.sync('test/**', {cwd: 'C:\\'})
[ 'test',
  'test\\deep',
  'test\\deep\\test.js',
  'test\\deep\\test.txt',
  'test\\test.js',
  'test\\test.txt' ]

Instead, I see:

> glob.sync('/test/*')
[ '\\test/deep',
  '\\test/test.js',
  '\\test/test.txt' ]
> glob.sync('/test/**')
[ 'C:\\test',
  'C:\\test\\deep',
  'C:\\test\\test.js',
  'C:\\test\\test.txt' ]
> glob.sync('test/*', {cwd: 'C:\\'})
[ 'test/deep',
  'test/test.js',
  'test/test.txt' ]
> glob.sync('test/**', {cwd: 'C:\\'})
[ 'test',
  'test/deep',
  'test/deep/test.js',
  'test/deep/test.txt',
  'test/test.js',
  'test/test.txt' ]

Note the anomalies:

  • glob.sync('/test/*') returns the right entries, but with mixed separators
  • glob.sync('/test/**') returns exactly the right format, but misses the deep entries
  • glob.sync('test/*', {cwd: 'C:\\'}) gets the right values, but uses posix separators
  • glob.sync('test/**', {cwd: 'C:\\'}) gets the right values, but uses posix separators

So what I'm doing now is using that last one, and then re-prepending the leading slash, and passing it through path.resolve to get my environment-appropriate path. That works, but it would be really great if the library made it all transparent. But even then, the second command should be finding those deeper files, and it isn't. There's also no obvious explanation for why the format of the paths between the first and the second are different.

Any insight into these inconsistencies?

@litmit
Copy link
Contributor

litmit commented Jan 14, 2014

@isaacs Commit #b6f01f5 seems to be completely wrong!
Pattern syntax MUST be fixed and not depend on platform. But file paths when tested MAY be normalized by some way.

May be I don't understand something, but now we can't write a pattern that exact match filesystem entry [a] (or any other entry that uses reserved characters) on Windows .

process.platform='win32'; // dirty hack, testing purposes only
var mm = require('minimatch');
mm('[a]', '[a]'); // false as suspected
mm('[a]', '\\[a\\]'); // false, THAT BUG
mm('[a]', '?a?'); // true, but not exact match only [a]
process.platform='linux'; // dirty hack, testing purposes only
var mm = require('minimatch');
mm('[a]', '[a]'); // false as suspected
mm('[a]', '\\[a\\]'); // true as suspected

Please, revert this commit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants