Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
path: fix posix.relative() on Windows
Fixes: #13683
PR-URL: #37747
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
|
|
@@ -23,11 +23,15 @@ |
|
|
|
|
|
const { |
|
|
FunctionPrototypeBind, |
|
|
RegExp, |
|
|
StringPrototypeCharCodeAt, |
|
|
StringPrototypeIndexOf, |
|
|
StringPrototypeLastIndexOf, |
|
|
StringPrototypeReplace, |
|
|
StringPrototypeSlice, |
|
|
StringPrototypeToLowerCase, |
|
|
} = primordials; |
|
|
|
|
|
const { |
|
|
CHAR_UPPERCASE_A, |
|
|
CHAR_LOWERCASE_A, |
|
|
@@ -1014,7 +1018,17 @@ const posix = { |
|
|
let resolvedAbsolute = false; |
|
|
|
|
|
for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) { |
|
|
const path = i >= 0 ? args[i] : process.cwd(); |
|
|
let path; |
|
|
if (i >= 0) { |
|
|
path = args[i]; |
|
|
} else { |
|
|
const _ = StringPrototypeReplace( |
|
|
process.cwd(), |
|
|
new RegExp(`\\${module.exports.sep}`, 'g'), |
|
|
posix.sep |
|
|
); |
|
|
path = StringPrototypeSlice(_, StringPrototypeIndexOf(_, posix.sep)); |
|
|
} |
|
|
|
|
|
validateString(path, 'path'); |
|
|
|
|
|
|
|
|
@@ -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 |
File renamed without changes.
|
|
@@ -9,6 +9,14 @@ const failures = []; |
|
|
const slashRE = /\//g; |
|
|
const backslashRE = /\\/g; |
|
|
|
|
|
const posixyCwd = common.isWindows ? |
|
|
(() => { |
|
|
const _ = process.cwd() |
|
|
.replaceAll(path.sep, path.posix.sep); |
|
|
return _.slice(_.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'], |
|
|
], |
|
|
|