Permalink
Browse files

url: keep auth in `url.resolve()` if host matches

Fixes: #8165

PR-URL: #8215
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
imyller authored and Fishrock123 committed Aug 19, 2016
1 parent eec5d02 commit 6ae7af0fa3e91681bc1dfb05a9b651a5ce5e12da
Showing with 5 additions and 2 deletions.
  1. +2 −2 lib/url.js
  2. +3 −0 test/parallel/test-url.js
View
@@ -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;
@@ -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]);

0 comments on commit 6ae7af0

Please sign in to comment.