summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmir Saboury <amir.saboury@gmail.com>2015-01-11 17:55:12 -0500
committerTrevor Norris <trev.norris@gmail.com>2015-02-09 14:49:10 -0700
commitad0684807c474db5cda7d28592e34e19910eb7ab (patch)
treed4f5ee198e0da4a07cd8d421c734fca762be21de
parent431eb172f97434a3b0868a610bc14d8ff7d9efd9 (diff)
downloadnode-ad0684807c474db5cda7d28592e34e19910eb7ab.tar.gz
url: reslove urls with . and ..
'.' and '..' are directory specs and resolving urls with or without the hostname with '.' and '..' should add a trailing slash to the end of the url. Fixes: https://github.com/joyent/node/issues/8992 PR-URL: https://github.com/joyent/node/pull/9010 Reviewed-by: Trevor Norris <trev.norris@gmail.com>
-rw-r--r--lib/url.js4
-rw-r--r--test/simple/test-url.js8
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/url.js b/lib/url.js
index d5948e450..e991f6d63 100644
--- a/lib/url.js
+++ b/lib/url.js
@@ -600,8 +600,8 @@ Url.prototype.resolveObject = function(relative) {
// then it must NOT get a trailing slash.
var last = srcPath.slice(-1)[0];
var hasTrailingSlash = (
- (result.host || relative.host) && (last === '.' || last === '..') ||
- last === '');
+ (result.host || relative.host || srcPath.length > 1) &&
+ (last === '.' || last === '..') || last === '');
// strip single dots, resolve double dots to parent dir
// if the path tries to go above the root, `up` ends up > 0
diff --git a/test/simple/test-url.js b/test/simple/test-url.js
index 95f50a23c..6c807930b 100644
--- a/test/simple/test-url.js
+++ b/test/simple/test-url.js
@@ -1087,6 +1087,14 @@ var relativeTests = [
['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'],
['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'],
['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'],
+ ['/foo', '.', '/'],
+ ['/foo', '..', '/'],
+ ['/foo/', '.', '/foo/'],
+ ['/foo/', '..', '/'],
+ ['/foo/bar', '.', '/foo/'],
+ ['/foo/bar', '..', '/'],
+ ['/foo/bar/', '.', '/foo/bar/'],
+ ['/foo/bar/', '..', '/foo/'],
['foo/bar', '../../../baz', '../../baz'],
['foo/bar/', '../../../baz', '../baz'],
['http://example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'],