Skip to content

Commit 0049e9a

Browse files
committed
always coerce cwd, root to '/' separated paths
Re: #467 PR-URL: #469 Credit: @isaacs Close: #469 Reviewed-by: @isaacs
1 parent a8a3682 commit 0049e9a

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ jobs:
3636
run: npm install
3737

3838
- name: Run Tests
39-
run: npm test -- -c -t0
39+
run: npm test -- -c -t0 --statements=80 --branches=80 --functions=80 --lines=80

common.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,26 @@ function setopts (self, pattern, options) {
8888
self.changedCwd = false
8989
var cwd = process.cwd()
9090
if (!ownProp(options, "cwd"))
91-
self.cwd = cwd
91+
self.cwd = path.resolve(cwd)
9292
else {
9393
self.cwd = path.resolve(options.cwd)
9494
self.changedCwd = self.cwd !== cwd
9595
}
9696

9797
self.root = options.root || path.resolve(self.cwd, "/")
9898
self.root = path.resolve(self.root)
99-
if (process.platform === "win32")
100-
self.root = self.root.replace(/\\/g, "/")
10199

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

105+
if (process.platform === "win32") {
106+
self.root = self.root.replace(/\\/g, "/")
107+
self.cwd = self.cwd.replace(/\\/g, "/")
108+
self.cwdAbs = self.cwdAbs.replace(/\\/g, "/")
109+
}
110+
109111
// disable comments and negation in Minimatch.
110112
// Note that they are not supported in Glob itself anyway.
111113
options.nonegate = true

test/cwd-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ tap.test("changing cwd and searching for **/d", function (t) {
6969
tap.test('non-dir cwd should raise error', function (t) {
7070
var notdir = 'a/b/c/d'
7171
var notdirRE = /a[\\\/]b[\\\/]c[\\\/]d/
72-
var abs = path.resolve(notdir)
72+
var abs = path.resolve(notdir).split('\\').join('/')
7373
var expect = new Error('ENOTDIR invalid cwd ' + abs)
7474
expect.code = 'ENOTDIR'
7575
expect.path = notdirRE

0 commit comments

Comments
 (0)