Skip to content

Commit

Permalink
url: fix inconsistent port in url.resolveObject
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
imyller authored and MylesBorins committed Oct 26, 2016
1 parent 055d39c commit be9d9bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion test/parallel/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,13 @@ var relativeTests2 = [
//changeing auth
['http://diff:[email protected]',
'http://asdf:[email protected]',
'http://diff:[email protected]/']
'http://diff:[email protected]/'],

// 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]);
Expand Down

0 comments on commit be9d9bd

Please sign in to comment.