diff --git a/lib/url.js b/lib/url.js index 64aa7bc59b3c85..0e15811a6c2045 100644 --- a/lib/url.js +++ b/lib/url.js @@ -780,13 +780,13 @@ Url.prototype.resolveObject = function(relative) { if (isRelAbs) { // it's absolute. if (relative.host || relative.host === '') { + if (result.host !== relative.host) result.auth = null; result.host = relative.host; result.port = relative.port; - result.auth = null; } if (relative.hostname || relative.hostname === '') { + if (result.hostname !== relative.hostname) result.auth = null; result.hostname = relative.hostname; - result.auth = null; } result.search = relative.search; result.query = relative.query; diff --git a/test/parallel/test-url.js b/test/parallel/test-url.js index 613dceca5f6eb6..b9f1e7b62f0a64 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -1588,6 +1588,9 @@ var relativeTests2 = [ ['mailto:another.host.com', 'mailto:user@example.org', 'mailto:another.host.com'], + ['https://example.com/foo', + 'https://user:password@example.com', + 'https://user:password@example.com/foo'], ]; relativeTests2.forEach(function(relativeTest) { const a = url.resolve(relativeTest[1], relativeTest[0]);