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

Commit 9b534e2

Browse files
amir-sJulien Gilli
authored andcommitted
url: resolve 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. Reviewed-By: Colin Ihrig <cjihrig@gmail.com> PR-URL: #9427
1 parent ae58fc4 commit 9b534e2

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/url.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,8 @@ Url.prototype.resolveObject = function(relative) {
641641
// then it must NOT get a trailing slash.
642642
var last = srcPath.slice(-1)[0];
643643
var hasTrailingSlash = (
644-
(result.host || relative.host) && (last === '.' || last === '..') ||
645-
last === '');
644+
(result.host || relative.host || srcPath.length > 1) &&
645+
(last === '.' || last === '..') || last === '');
646646

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

test/simple/test-url.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,14 @@ var relativeTests = [
11781178
['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'],
11791179
['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'],
11801180
['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'],
1181+
['/foo', '.', '/'],
1182+
['/foo', '..', '/'],
1183+
['/foo/', '.', '/foo/'],
1184+
['/foo/', '..', '/'],
1185+
['/foo/bar', '.', '/foo/'],
1186+
['/foo/bar', '..', '/'],
1187+
['/foo/bar/', '.', '/foo/bar/'],
1188+
['/foo/bar/', '..', '/foo/'],
11811189
['foo/bar', '../../../baz', '../../baz'],
11821190
['foo/bar/', '../../../baz', '../baz'],
11831191
['http://example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'],

0 commit comments

Comments
 (0)