diff options
author | Rich Trott <rtrott@gmail.com> | 2021-03-13 18:33:07 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2021-04-02 19:30:43 -0700 |
commit | b0d5e036d8677633d82032deac055ad716a55531 (patch) | |
tree | 39fda131169f0d2c5d7d4df0483f050d21cb373a /lib | |
parent | e46c680bf2b211bbd52cf959ca17ee98c7f657f5 (diff) | |
download | node-new-b0d5e036d8677633d82032deac055ad716a55531.tar.gz |
path: fix posix.relative() on Windows
Fixes: https://github.com/nodejs/node/issues/13683
PR-URL: https://github.com/nodejs/node/pull/37747
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/path.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/path.js b/lib/path.js index 6001b0ba83..95cb3201bf 100644 --- a/lib/path.js +++ b/lib/path.js @@ -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'); |