Skip to content

Commit 30cec18

Browse files
mscdexrvagg
authored andcommitted
path: fix verbose relative() output
Fixes: #5383 PR-URL: #5389 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
1 parent 378a772 commit 30cec18

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/path.js

+4
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,10 @@ const posix = {
12811281
// We get here if `from` is the exact base path for `to`.
12821282
// For example: from='/foo/bar'; to='/foo/bar/baz'
12831283
return to.slice(i + 2);
1284+
} else if (fromLen > length && from.charCodeAt(i + 1) === 47/*/*/) {
1285+
// We get here if `to` is the exact base path for `from`.
1286+
// For example: from='/foo/bar/baz'; to='/foo/bar'
1287+
lastCommonSep = i;
12841288
}
12851289
break;
12861290
}

test/parallel/test-path.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ const relativeTests = [
481481
['/var/lib', '/var/apache', '../apache'],
482482
['/var/', '/var/lib', 'lib'],
483483
['/', '/var/lib', 'var/lib'],
484-
['/foo/test', '/foo/test/bar/package.json', 'bar/package.json']
484+
['/foo/test', '/foo/test/bar/package.json', 'bar/package.json'],
485+
['/Users/a/web/b/test/mails', '/Users/a/web/b', '../..']
485486
]
486487
]
487488
];

0 commit comments

Comments
 (0)