diff --git a/lib/path.js b/lib/path.js index f6a2f032230dd2..0dbd2a641c4d89 100644 --- a/lib/path.js +++ b/lib/path.js @@ -1281,6 +1281,10 @@ const posix = { // We get here if `from` is the exact base path for `to`. // For example: from='/foo/bar'; to='/foo/bar/baz' return to.slice(i + 2); + } else if (fromLen > length && from.charCodeAt(i + 1) === 47/*/*/) { + // We get here if `to` is the exact base path for `from`. + // For example: from='/foo/bar/baz'; to='/foo/bar' + lastCommonSep = i; } break; } diff --git a/test/parallel/test-path.js b/test/parallel/test-path.js index aeb6ec0c49bbf7..411231e709861b 100644 --- a/test/parallel/test-path.js +++ b/test/parallel/test-path.js @@ -481,7 +481,8 @@ const relativeTests = [ ['/var/lib', '/var/apache', '../apache'], ['/var/', '/var/lib', 'lib'], ['/', '/var/lib', 'var/lib'], - ['/foo/test', '/foo/test/bar/package.json', 'bar/package.json'] + ['/foo/test', '/foo/test/bar/package.json', 'bar/package.json'], + ['/Users/a/web/b/test/mails', '/Users/a/web/b', '../..'] ] ] ];