diff --git a/lib/url.js b/lib/url.js index 1683f905037c52..58104bf2a8f44b 100644 --- a/lib/url.js +++ b/lib/url.js @@ -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); @@ -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; diff --git a/test/parallel/test-url.js b/test/parallel/test-url.js index 121d6caaf612e3..83b04fa0e46107 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -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]),