Skip to content

Commit

Permalink
url: drop auth in url.resolve() if host changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Apr 20, 2015
1 parent 6870764 commit 837b7de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ Url.prototype.resolveObject = function(relative) {
if (relative.protocol) {
relative.hostname = null;
relative.port = null;
result.auth = null;
if (relative.host) {
if (relPath[0] === '') relPath[0] = relative.host;
else relPath.unshift(relative.host);
Expand All @@ -564,10 +565,14 @@ Url.prototype.resolveObject = function(relative) {

if (isRelAbs) {
// it's absolute.
result.host = (relative.host || relative.host === '') ?
relative.host : result.host;
result.hostname = (relative.hostname || relative.hostname === '') ?
relative.hostname : result.hostname;
if (relative.host || relative.host === '') {
result.host = relative.host;
result.auth = null;
}
if (relative.hostname || relative.hostname === '') {
result.hostname = relative.hostname;
result.auth = null;
}
result.search = relative.search;
result.query = relative.query;
srcPath = relPath;
Expand Down
16 changes: 15 additions & 1 deletion test/parallel/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,21 @@ var relativeTests2 = [
//changeing auth
['http://diff:auth@www.example.com',
'http://asdf:qwer@www.example.com',
'http://diff:auth@www.example.com/']
'http://diff:auth@www.example.com/'],

// https://github.com/iojs/io.js/issues/1435
['https://another.host.com/',
'https://user:password@example.org/',
'https://another.host.com/'],
['//another.host.com/',
'https://user:password@example.org/',
'https://another.host.com/'],
['http://another.host.com/',
'https://user:password@example.org/',
'http://another.host.com/'],
['mailto:another.host.com',
'mailto:user@example.org',
'mailto:another.host.com'],
];
relativeTests2.forEach(function(relativeTest) {
var a = url.resolve(relativeTest[1], relativeTest[0]),
Expand Down

0 comments on commit 837b7de

Please sign in to comment.