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 <jasnell@gmail.com>
  • Loading branch information
imyller authored and Myles Borins committed Sep 30, 2016
1 parent d0a4f20 commit 2362504
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: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]);
Expand Down

0 comments on commit 2362504

Please sign in to comment.