diff --git a/lib/path.js b/lib/path.js index f3d7f42fc1f433..8ba229a670ab2b 100644 --- a/lib/path.js +++ b/lib/path.js @@ -23,6 +23,7 @@ const { FunctionPrototypeBind, + RegExp, StringPrototypeCharCodeAt, StringPrototypeLastIndexOf, StringPrototypeSlice, @@ -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'); diff --git a/test/known_issues/known_issues.status b/test/known_issues/known_issues.status index 690e6e9840b77c..7a50c10404c723 100644 --- a/test/known_issues/known_issues.status +++ b/test/known_issues/known_issues.status @@ -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 diff --git a/test/known_issues/test-path-posix-relative-on-windows.js b/test/parallel/test-path-posix-relative-on-windows.js similarity index 100% rename from test/known_issues/test-path-posix-relative-on-windows.js rename to test/parallel/test-path-posix-relative-on-windows.js diff --git a/test/parallel/test-path-resolve.js b/test/parallel/test-path-resolve.js index ed3c7c4c5a0113..859b1d1e52489d 100644 --- a/test/parallel/test-path-resolve.js +++ b/test/parallel/test-path-resolve.js @@ -9,6 +9,14 @@ const failures = []; const slashRE = /\//g; const backslashRE = /\\/g; +const posixyCwd = common.isWindows ? + (() => { + const _ = process.cwd() + .replace(new RegExp(`\\${path.sep}`, 'g'), path.posix.sep); + return _.substr(_.indexOf(path.posix.sep)); + })() : + process.cwd(); + const resolveTests = [ [ path.win32.resolve, // Arguments result @@ -31,8 +39,8 @@ const resolveTests = [ // Arguments result [[['/var/lib', '../', 'file/'], '/var/file'], [['/var/lib', '/../', 'file/'], '/file'], - [['a/b/c/', '../../..'], process.cwd()], - [['.'], process.cwd()], + [['a/b/c/', '../../..'], posixyCwd], + [['.'], posixyCwd], [['/some/dir', '.', '/absolute/'], '/absolute'], [['/foo/tmp.3/', '../tmp.3/cycles/root.js'], '/foo/tmp.3/cycles/root.js'] ]