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]);