Skip to content

Commit faa687b

Browse files
amir-scjihrig
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: nodejs/node-v0.x-archive#8992 PR-URL: #278 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent cca8de6 commit faa687b

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
@@ -619,8 +619,8 @@ Url.prototype.resolveObject = function(relative) {
619619
// then it must NOT get a trailing slash.
620620
var last = srcPath.slice(-1)[0];
621621
var hasTrailingSlash = (
622-
(result.host || relative.host) && (last === '.' || last === '..') ||
623-
last === '');
622+
(result.host || relative.host || srcPath.length > 1) &&
623+
(last === '.' || last === '..') || last === '');
624624

625625
// strip single dots, resolve double dots to parent dir
626626
// 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
@@ -1157,6 +1157,14 @@ var relativeTests = [
11571157
['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'],
11581158
['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'],
11591159
['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'],
1160+
['/foo', '.', '/'],
1161+
['/foo', '..', '/'],
1162+
['/foo/', '.', '/foo/'],
1163+
['/foo/', '..', '/'],
1164+
['/foo/bar', '.', '/foo/'],
1165+
['/foo/bar', '..', '/'],
1166+
['/foo/bar/', '.', '/foo/bar/'],
1167+
['/foo/bar/', '..', '/foo/'],
11601168
['foo/bar', '../../../baz', '../../baz'],
11611169
['foo/bar/', '../../../baz', '../baz'],
11621170
['http://example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'],

0 commit comments

Comments
 (0)