Skip to content

Commit

Permalink
path: fix posix.relative() on Windows
Browse files Browse the repository at this point in the history
Fixes: #13683
  • Loading branch information
Trott committed Mar 14, 2021
1 parent 85edaf4 commit 74a9593
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
10 changes: 9 additions & 1 deletion lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

const {
FunctionPrototypeBind,
RegExp,
StringPrototypeCharCodeAt,
StringPrototypeLastIndexOf,
StringPrototypeSlice,
Expand Down Expand Up @@ -1014,7 +1015,14 @@ const posix = {
let resolvedAbsolute = false;

for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
const path = i >= 0 ? args[i] : process.cwd();
const path = i >= 0 ?
args[i] :
(() => {
const _ = process.cwd()
.replace(new RegExp(`\\${module.exports.sep}`, 'g'), posix.sep);
return _.substr(_.indexOf(posix.sep));
})();


validateString(path, 'path');

Expand Down
14 changes: 0 additions & 14 deletions test/known_issues/known_issues.status
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,18 @@ test-vm-timeout-escape-queuemicrotask: SKIP
[$system==win32]

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

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

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

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

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

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

[$system==ibmi]
# Windows-specific test
test-path-posix-relative-on-windows: SKIP
7 changes: 7 additions & 0 deletions test/parallel/test-path-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const failures = [];
const slashRE = /\//g;
const backslashRE = /\\/g;

const cwd = common.isWindows ?
(() => { process.cwd()
.replace(new RegExp(`\\${module.exports.sep}`, 'g'), posix.sep);
return _.substr(_.indexOf(posix.sep));
})() :
process.cwd();

const resolveTests = [
[ path.win32.resolve,
// Arguments result
Expand Down

0 comments on commit 74a9593

Please sign in to comment.