From aaae94ea7ebf1bff8e79eb013cc78a6c323a9c09 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 Signed-off-by: Ilkka Myller --- 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 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]);