Skip to content

Commit be9d9bd

Browse files
imyllerMylesBorins
authored andcommitted
url: fix inconsistent port in url.resolveObject
This commit fixes bug where url.resolveObject returns conflicting host and port values. Fixes: #8213 Ref: #8872 PR-URL: #8214 Reviewed-By: James M Snell <[email protected]>
1 parent 055d39c commit be9d9bd

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/url.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,10 @@ Url.prototype.resolveObject = function(relative) {
564564

565565
if (isRelAbs) {
566566
// it's absolute.
567-
result.host = (relative.host || relative.host === '') ?
568-
relative.host : result.host;
567+
if (relative.host || relative.host === '') {
568+
result.host = relative.host;
569+
result.port = relative.port;
570+
}
569571
result.hostname = (relative.hostname || relative.hostname === '') ?
570572
relative.hostname : result.hostname;
571573
result.search = relative.search;

test/parallel/test-url.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,13 @@ var relativeTests2 = [
15131513
//changeing auth
15141514
['http://diff:[email protected]',
15151515
'http://asdf:[email protected]',
1516-
'http://diff:[email protected]/']
1516+
'http://diff:[email protected]/'],
1517+
1518+
// changing port
1519+
['https://example.com:81/',
1520+
'https://example.com:82/',
1521+
'https://example.com:81/']
1522+
15171523
];
15181524
relativeTests2.forEach(function(relativeTest) {
15191525
const a = url.resolve(relativeTest[1], relativeTest[0]);

0 commit comments

Comments
 (0)