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

PR-URL: #8215
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
imyller authored and jasnell committed Aug 24, 2016
1 parent 09f861f commit 51f96df
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:[email protected]',
'mailto:another.host.com'],
['https://example.com/foo',
'https://user:[email protected]',
'https://user:[email protected]/foo'],
];
relativeTests2.forEach(function(relativeTest) {
const a = url.resolve(relativeTest[1], relativeTest[0]);
Expand Down

0 comments on commit 51f96df

Please sign in to comment.