From be9d9bd7c3a6e1fe7bd2aa27176920f9dc73c09d Mon Sep 17 00:00:00 2001 From: Ilkka Myller Date: Sun, 21 Aug 2016 23:23:31 +0300 Subject: [PATCH] url: fix inconsistent port in url.resolveObject This commit fixes bug where url.resolveObject returns conflicting host and port values. Fixes: https://github.com/nodejs/node/issues/8213 Ref: https://github.com/nodejs/node/pull/8872 PR-URL: https://github.com/nodejs/node/pull/8214 Reviewed-By: James M Snell --- lib/url.js | 6 ++++-- test/parallel/test-url.js | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/url.js b/lib/url.js index d3fcdc3c1366ef..f2a627fbbeaf9e 100644 --- a/lib/url.js +++ b/lib/url.js @@ -564,8 +564,10 @@ Url.prototype.resolveObject = function(relative) { if (isRelAbs) { // it's absolute. - result.host = (relative.host || relative.host === '') ? - relative.host : result.host; + if (relative.host || relative.host === '') { + result.host = relative.host; + result.port = relative.port; + } result.hostname = (relative.hostname || relative.hostname === '') ? relative.hostname : result.hostname; result.search = relative.search; diff --git a/test/parallel/test-url.js b/test/parallel/test-url.js index b395c8909696b0..164e6dcebf2d1f 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -1513,7 +1513,13 @@ 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/'], + + // changing port + ['https://example.com:81/', + 'https://example.com:82/', + 'https://example.com:81/'] + ]; relativeTests2.forEach(function(relativeTest) { const a = url.resolve(relativeTest[1], relativeTest[0]);