Skip to content

Commit

Permalink
url: keep auth in url.resolve() if host matches
Browse files Browse the repository at this point in the history
Fixes: #8165

Signed-off-by: Ilkka Myller <ilkka.myller@nodefield.com>
  • Loading branch information
imyller committed Aug 24, 2016
1 parent 09f861f commit aaae94e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,13 @@ Url.prototype.resolveObject = function(relative) {
if (isRelAbs) {
// it's absolute.
if (relative.host || relative.host === '') {
if (result.host !== relative.host) result.auth = null;
result.host = relative.host;
result.port = relative.port;
result.auth = null;
}
if (relative.hostname || relative.hostname === '') {
if (result.hostname !== relative.hostname) result.auth = null;
result.hostname = relative.hostname;
result.auth = null;
}
result.search = relative.search;
result.query = relative.query;
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,9 @@ var relativeTests2 = [
['mailto:another.host.com',
'mailto:user@example.org',
'mailto:another.host.com'],
['https://example.com/foo',
'https://user:password@example.com',
'https://user:password@example.com/foo'],
];
relativeTests2.forEach(function(relativeTest) {
const a = url.resolve(relativeTest[1], relativeTest[0]);
Expand Down

0 comments on commit aaae94e

Please sign in to comment.