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>
pull/23391/head
Amir Saboury 2015-01-11 17:55:12 -05:00 committed by Trevor Norris
parent 431eb172f9
commit ad0684807c
2 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -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'],