Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit ad06848

Browse files
amir-strevnorris
authored andcommitted
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: #8992 PR-URL: #9010 Reviewed-by: Trevor Norris <trev.norris@gmail.com>
1 parent 431eb17 commit ad06848

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
@@ -600,8 +600,8 @@ Url.prototype.resolveObject = function(relative) {
600600
// then it must NOT get a trailing slash.
601601
var last = srcPath.slice(-1)[0];
602602
var hasTrailingSlash = (
603-
(result.host || relative.host) && (last === '.' || last === '..') ||
604-
last === '');
603+
(result.host || relative.host || srcPath.length > 1) &&
604+
(last === '.' || last === '..') || last === '');
605605

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

test/simple/test-url.js

+8
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,14 @@ var relativeTests = [
10871087
['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'],
10881088
['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'],
10891089
['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'],
1090+
['/foo', '.', '/'],
1091+
['/foo', '..', '/'],
1092+
['/foo/', '.', '/foo/'],
1093+
['/foo/', '..', '/'],
1094+
['/foo/bar', '.', '/foo/'],
1095+
['/foo/bar', '..', '/'],
1096+
['/foo/bar/', '.', '/foo/bar/'],
1097+
['/foo/bar/', '..', '/foo/'],
10901098
['foo/bar', '../../../baz', '../../baz'],
10911099
['foo/bar/', '../../../baz', '../baz'],
10921100
['http://example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'],

0 commit comments

Comments
 (0)