Skip to content

Commit

Permalink
Fix path.relative UNC path result
Browse files Browse the repository at this point in the history
When the result of a path.relative() is an absolute UNC path, it should
include the leading backslashes.

Fixes: #8444
  • Loading branch information
jasongin committed Sep 13, 2016
1 parent 53178f9 commit 5712f33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 1 addition & 5 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,8 @@ const win32 = {

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

var out = '';
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,9 @@ const relativeTests = [
['C:\\baz-quux', 'C:\\baz', '..\\baz'],
['C:\\baz', 'C:\\baz-quux', '..\\baz-quux'],
['\\\\foo\\baz-quux', '\\\\foo\\baz', '..\\baz'],
['\\\\foo\\baz', '\\\\foo\\baz-quux', '..\\baz-quux']
['\\\\foo\\baz', '\\\\foo\\baz-quux', '..\\baz-quux'],
['C:\\baz', '\\\\foo\\bar\\baz', '\\\\foo\\bar\\baz'],
['\\\\foo\\bar\\baz', 'C:\\baz', 'C:\\baz']
]
],
[ path.posix.relative,
Expand Down

0 comments on commit 5712f33

Please sign in to comment.