Skip to content

Commit c1e47ed

Browse files
jasonginjasnell
authored andcommitted
path: fix path.relative UNC path result
When the result of a path.relative() is an absolute UNC path, it should include the leading backslashes. Fixes: #8444 PR-URL: #8523 Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]>
1 parent 0f7fffb commit c1e47ed

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

lib/path.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,8 @@ const win32 = {
619619

620620
// We found a mismatch before the first common path separator was seen, so
621621
// return the original `to`.
622-
// TODO: do this just for device roots (and not UNC paths)?
623622
if (i !== length && lastCommonSep === -1) {
624-
if (toStart > 0)
625-
return toOrig.slice(toStart);
626-
else
627-
return toOrig;
623+
return toOrig;
628624
}
629625

630626
var out = '';

test/parallel/test-path.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ const relativeTests = [
492492
['C:\\baz-quux', 'C:\\baz', '..\\baz'],
493493
['C:\\baz', 'C:\\baz-quux', '..\\baz-quux'],
494494
['\\\\foo\\baz-quux', '\\\\foo\\baz', '..\\baz'],
495-
['\\\\foo\\baz', '\\\\foo\\baz-quux', '..\\baz-quux']
495+
['\\\\foo\\baz', '\\\\foo\\baz-quux', '..\\baz-quux'],
496+
['C:\\baz', '\\\\foo\\bar\\baz', '\\\\foo\\bar\\baz'],
497+
['\\\\foo\\bar\\baz', 'C:\\baz', 'C:\\baz']
496498
]
497499
],
498500
[ path.posix.relative,

0 commit comments

Comments
 (0)