Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-07-05 14:49:40 +0300
committerzhangyongsheng <zhangyongsheng@youzan.com>2019-07-14 05:46:53 +0300
commit5a6aa66afa189882462761bbb294a8adb86430ae (patch)
treee12b067201b5042cd8eed7a1d1c3cf815ec74e6f /lib/path.js
parentc31f7e595af85da8ada5d278e6e96e8537b57435 (diff)
path: using .relative() should not return a trailing slash
Resolving a path against root with `path.relative()` should not include a trailing slash. Fixes: https://github.com/nodejs/node/issues/28549 PR-URL: https://github.com/nodejs/node/pull/28556 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Diffstat (limited to 'lib/path.js')
-rw-r--r--lib/path.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/path.js b/lib/path.js
index 2301a6ebb83..f7a8612933a 100644
--- a/lib/path.js
+++ b/lib/path.js
@@ -1090,11 +1090,16 @@ const posix = {
// For example: from='/'; to='/foo'
return to.slice(toStart + i);
}
- } else if (fromLen > length &&
- from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
- // We get here if `to` is the exact base path for `from`.
- // For example: from='/foo/bar/baz'; to='/foo/bar'
- lastCommonSep = i;
+ } else if (fromLen > length) {
+ if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
+ // We get here if `to` is the exact base path for `from`.
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
+ lastCommonSep = i;
+ } else if (i === 0) {
+ // We get here if `to` is the root.
+ // For example: from='/foo/bar'; to='/'
+ lastCommonSep = 0;
+ }
}
}