Browse Source

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 <me@silverwind.io>
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Evan Lucas <evanlucas@me.com>
process-exit-stdio-flushing
Brian White 9 years ago
committed by Roman Reiss
parent
commit
3a331b66f8
  1. 4
      lib/path.js
  2. 3
      test/parallel/test-path.js

4
lib/path.js

@ -1282,6 +1282,10 @@ const posix = {
// We get here if `from` is the exact base path for `to`. // We get here if `from` is the exact base path for `to`.
// For example: from='/foo/bar'; to='/foo/bar/baz' // For example: from='/foo/bar'; to='/foo/bar/baz'
return to.slice(i + 2); 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; break;
} }

3
test/parallel/test-path.js

@ -481,7 +481,8 @@ const relativeTests = [
['/var/lib', '/var/apache', '../apache'], ['/var/lib', '/var/apache', '../apache'],
['/var/', '/var/lib', 'lib'], ['/var/', '/var/lib', 'lib'],
['/', '/var/lib', 'var/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', '../..']
] ]
] ]
]; ];

Loading…
Cancel
Save