Skip to content

Commit 3a331b6

Browse files
mscdexsilverwind
authored andcommitted
path: fix verbose relative() output
Fixes: #5383 PR-URL: #5389 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Evan Lucas <evanlucas@me.com>
1 parent 5298c81 commit 3a331b6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/path.js

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

test/parallel/test-path.js

Lines changed: 2 additions & 1 deletion
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)