Skip to content

Commit

Permalink
always coerce cwd, root to '/' separated paths
Browse files Browse the repository at this point in the history
Re: #467

PR-URL: #469
Credit: @isaacs
Close: #469
Reviewed-by: @isaacs
  • Loading branch information
isaacs committed May 12, 2022
1 parent a8a3682 commit 0049e9a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
run: npm install

- name: Run Tests
run: npm test -- -c -t0
run: npm test -- -c -t0 --statements=80 --branches=80 --functions=80 --lines=80
12 changes: 7 additions & 5 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,26 @@ function setopts (self, pattern, options) {
self.changedCwd = false
var cwd = process.cwd()
if (!ownProp(options, "cwd"))
self.cwd = cwd
self.cwd = path.resolve(cwd)
else {
self.cwd = path.resolve(options.cwd)
self.changedCwd = self.cwd !== cwd
}

self.root = options.root || path.resolve(self.cwd, "/")
self.root = path.resolve(self.root)
if (process.platform === "win32")
self.root = self.root.replace(/\\/g, "/")

// TODO: is an absolute `cwd` supposed to be resolved against `root`?
// e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd)
if (process.platform === "win32")
self.cwdAbs = self.cwdAbs.replace(/\\/g, "/")
self.nomount = !!options.nomount

if (process.platform === "win32") {
self.root = self.root.replace(/\\/g, "/")
self.cwd = self.cwd.replace(/\\/g, "/")
self.cwdAbs = self.cwdAbs.replace(/\\/g, "/")
}

// disable comments and negation in Minimatch.
// Note that they are not supported in Glob itself anyway.
options.nonegate = true
Expand Down
2 changes: 1 addition & 1 deletion test/cwd-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ tap.test("changing cwd and searching for **/d", function (t) {
tap.test('non-dir cwd should raise error', function (t) {
var notdir = 'a/b/c/d'
var notdirRE = /a[\\\/]b[\\\/]c[\\\/]d/
var abs = path.resolve(notdir)
var abs = path.resolve(notdir).split('\\').join('/')
var expect = new Error('ENOTDIR invalid cwd ' + abs)
expect.code = 'ENOTDIR'
expect.path = notdirRE
Expand Down

0 comments on commit 0049e9a

Please sign in to comment.