From 73073672b8e56b87e3e63abbf9b8ac975df8e5b1 Mon Sep 17 00:00:00 2001 From: Ilkka Myller Date: Fri, 19 Aug 2016 22:59:20 +0300 Subject: [PATCH] url: keep auth in `url.resolve()` if host matches Fixes: https://github.com/nodejs/node/issues/8165 PR-URL: https://github.com/nodejs/node/pull/8215 Reviewed-By: James M Snell --- lib/url.js | 4 ++-- test/parallel/test-url.js | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/url.js b/lib/url.js index 5f4b1cf8ccbd78..b3083abfde9f41 100644 --- a/lib/url.js +++ b/lib/url.js @@ -775,13 +775,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 9e047ef7008bac..b8548f46e4c241 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -1571,6 +1571,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]);