From 30cec18eeb79b2daf922464f611e16e5f6fc697b Mon Sep 17 00:00:00 2001 From: Brian White Date: Tue, 23 Feb 2016 10:13:16 -0500 Subject: [PATCH] path: fix verbose relative() output Fixes: https://github.com/nodejs/node/issues/5383 PR-URL: https://github.com/nodejs/node/pull/5389 Reviewed-By: Roman Reiss Reviewed-By: Rod Vagg Reviewed-By: Evan Lucas --- lib/path.js | 4 ++++ test/parallel/test-path.js | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) 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', '../..'] ] ] ];