From 0dade15fb9eb60d9bde63b6d6d544977fee72e17 Mon Sep 17 00:00:00 2001 From: Amir Saboury Date: Fri, 9 Jan 2015 22:01:32 -0500 Subject: [PATCH] url: resloving urls without hostname with . & .. --- lib/url.js | 4 ++-- test/parallel/test-url.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/url.js b/lib/url.js index f2219580a7ce25..7178d88b76c831 100644 --- a/lib/url.js +++ b/lib/url.js @@ -663,8 +663,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/parallel/test-url.js b/test/parallel/test-url.js index f12a00dbed0b72..ce356d11890f96 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -1231,6 +1231,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'],