Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
url: fix inconsistent port in url.resolveObject
This commit fixes bug where url.resolveObject returns conflicting
host and port values.

Fixes: #8213
PR-URL: #8214
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
imyller committed Sep 30, 2016
commit a0d55cbcb2b5c7e44dbf8d7e295f35c117dcac45
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