url: fix inconsistent port in url.resolveObject

This commit fixes bug where url.resolveObject returns conflicting
host and port values.

Fixes: https://github.com/nodejs/node/issues/8213
PR-URL: https://github.com/nodejs/node/pull/8214
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ilkka Myller 2016-08-21 23:23:31 +03:00 committed by James M Snell
parent b4ea3a08f1
commit 286d44e43d
2 changed files with 6 additions and 0 deletions

View File

@ -781,6 +781,7 @@ Url.prototype.resolveObject = function(relative) {
// it's absolute. // it's absolute.
if (relative.host || relative.host === '') { if (relative.host || relative.host === '') {
result.host = relative.host; result.host = relative.host;
result.port = relative.port;
result.auth = null; result.auth = null;
} }
if (relative.hostname || relative.hostname === '') { if (relative.hostname || relative.hostname === '') {

View File

@ -1570,6 +1570,11 @@ var relativeTests2 = [
'http://asdf:qwer@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/'],
// https://github.com/nodejs/node/issues/1435 // https://github.com/nodejs/node/issues/1435
['https://another.host.com/', ['https://another.host.com/',
'https://user:password@example.org/', 'https://user:password@example.org/',