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 <jasnell@gmail.com>
  • Loading branch information
imyller authored and Fishrock123 committed Sep 9, 2016
1 parent eec5d02 commit 6ae7af0
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 @@ -775,13 +775,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 @@ -1571,6 +1571,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 6ae7af0

Please sign in to comment.