Skip to content

Commit 0dade15

Browse files
committed
url: resloving urls without hostname with . & ..
1 parent a80b977 commit 0dade15

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/url.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ Url.prototype.resolveObject = function(relative) {
663663
// then it must NOT get a trailing slash.
664664
var last = srcPath.slice(-1)[0];
665665
var hasTrailingSlash = (
666-
(result.host || relative.host) && (last === '.' || last === '..') ||
667-
last === '');
666+
(result.host || relative.host || srcPath.length > 1) &&
667+
(last === '.' || last === '..') || last === '');
668668

669669
// strip single dots, resolve double dots to parent dir
670670
// if the path tries to go above the root, `up` ends up > 0

test/parallel/test-url.js

+8
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,14 @@ var relativeTests = [
12311231
['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'],
12321232
['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'],
12331233
['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'],
1234+
['/foo', '.', '/'],
1235+
['/foo', '..', '/'],
1236+
['/foo/', '.', '/foo/'],
1237+
['/foo/', '..', '/'],
1238+
['/foo/bar', '.', '/foo/'],
1239+
['/foo/bar', '..', '/'],
1240+
['/foo/bar/', '.', '/foo/bar/'],
1241+
['/foo/bar/', '..', '/foo/'],
12341242
['foo/bar', '../../../baz', '../../baz'],
12351243
['foo/bar/', '../../../baz', '../baz'],
12361244
['http://example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'],

0 commit comments

Comments
 (0)