From: Amir Saboury Date: Sat, 10 Jan 2015 03:01:32 +0000 (-0500) Subject: url: reslove urls with . and .. X-Git-Tag: v1.3.0~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=faa687b4be2cea71c545cc1bec631c164b608acd;p=platform%2Fupstream%2Fnodejs.git 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/iojs/io.js/pull/278 Reviewed-By: Trevor Norris Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig --- diff --git a/lib/url.js b/lib/url.js index 65012cd..00e4ec9 100644 --- a/lib/url.js +++ b/lib/url.js @@ -619,8 +619,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 d6732a9..7b46fc9 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -1157,6 +1157,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'],