Skip to content

Commit 0b54e5b

Browse files
committed
path: fix posix.relative() on Windows
Fixes: #13683
1 parent 85edaf4 commit 0b54e5b

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

lib/path.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
const {
2525
FunctionPrototypeBind,
26+
RegExp,
2627
StringPrototypeCharCodeAt,
2728
StringPrototypeLastIndexOf,
2829
StringPrototypeSlice,
@@ -1014,7 +1015,14 @@ const posix = {
10141015
let resolvedAbsolute = false;
10151016

10161017
for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1017-
const path = i >= 0 ? args[i] : process.cwd();
1018+
const path = i >= 0 ?
1019+
args[i] :
1020+
(() => {
1021+
const _ = process.cwd()
1022+
.replace(new RegExp(`\\${module.exports.sep}`, 'g'), posix.sep);
1023+
return _.substr(_.indexOf(posix.sep));
1024+
})();
1025+
10181026

10191027
validateString(path, 'path');
10201028

test/known_issues/known_issues.status

-14
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,18 @@ test-vm-timeout-escape-queuemicrotask: SKIP
1515
[$system==win32]
1616

1717
[$system==linux]
18-
# Windows-specific test
19-
test-path-posix-relative-on-windows: SKIP
2018

2119
[$system==macos]
22-
# Windows-specific test
23-
test-path-posix-relative-on-windows: SKIP
2420

2521
[$system==solaris]
26-
# Windows-specific test
27-
test-path-posix-relative-on-windows: SKIP
2822

2923
[$system==freebsd]
30-
# Windows-specific test
31-
test-path-posix-relative-on-windows: SKIP
3224

3325
[$system==aix]
34-
# Windows-specific test
35-
test-path-posix-relative-on-windows: SKIP
3626

3727
[$arch==arm]
3828
# The Raspberry Pis are too slow to run this test.
3929
# See https://github.com/nodejs/build/issues/2227#issuecomment-608334574
4030
test-crypto-authenticated-stream: SKIP
41-
# Windows-specific test
42-
test-path-posix-relative-on-windows: SKIP
4331

4432
[$system==ibmi]
45-
# Windows-specific test
46-
test-path-posix-relative-on-windows: SKIP

test/parallel/test-path-resolve.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ const failures = [];
99
const slashRE = /\//g;
1010
const backslashRE = /\\/g;
1111

12+
const posixyCwd = common.isWindows ?
13+
(() => {
14+
const _ = process.cwd()
15+
.replace(new RegExp(`\\${module.exports.sep}`, 'g'), path.posix.sep);
16+
return _.substr(_.indexOf(path.posix.sep));
17+
})() :
18+
process.cwd();
19+
1220
const resolveTests = [
1321
[ path.win32.resolve,
1422
// Arguments result
@@ -31,8 +39,8 @@ const resolveTests = [
3139
// Arguments result
3240
[[['/var/lib', '../', 'file/'], '/var/file'],
3341
[['/var/lib', '/../', 'file/'], '/file'],
34-
[['a/b/c/', '../../..'], process.cwd()],
35-
[['.'], process.cwd()],
42+
[['a/b/c/', '../../..'], posixyCwd],
43+
[['.'], posixyCwd],
3644
[['/some/dir', '.', '/absolute/'], '/absolute'],
3745
[['/foo/tmp.3/', '../tmp.3/cycles/root.js'], '/foo/tmp.3/cycles/root.js']
3846
]

0 commit comments

Comments
 (0)