url: drop auth in url.resolve()
if host changes
Fixes: https://github.com/nodejs/node/issues/1435 PR-URL: https://github.com/nodejs/node/pull/1480 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
This commit is contained in:
parent
3ee68f794f
commit
eb4201f07a
13
lib/url.js
13
lib/url.js
@ -754,6 +754,7 @@ Url.prototype.resolveObject = function(relative) {
|
|||||||
if (relative.protocol) {
|
if (relative.protocol) {
|
||||||
relative.hostname = null;
|
relative.hostname = null;
|
||||||
relative.port = null;
|
relative.port = null;
|
||||||
|
result.auth = null;
|
||||||
if (relative.host) {
|
if (relative.host) {
|
||||||
if (relPath[0] === '') relPath[0] = relative.host;
|
if (relPath[0] === '') relPath[0] = relative.host;
|
||||||
else relPath.unshift(relative.host);
|
else relPath.unshift(relative.host);
|
||||||
@ -765,10 +766,14 @@ Url.prototype.resolveObject = function(relative) {
|
|||||||
|
|
||||||
if (isRelAbs) {
|
if (isRelAbs) {
|
||||||
// it's absolute.
|
// it's absolute.
|
||||||
result.host = (relative.host || relative.host === '') ?
|
if (relative.host || relative.host === '') {
|
||||||
relative.host : result.host;
|
result.host = relative.host;
|
||||||
result.hostname = (relative.hostname || relative.hostname === '') ?
|
result.auth = null;
|
||||||
relative.hostname : result.hostname;
|
}
|
||||||
|
if (relative.hostname || relative.hostname === '') {
|
||||||
|
result.hostname = relative.hostname;
|
||||||
|
result.auth = null;
|
||||||
|
}
|
||||||
result.search = relative.search;
|
result.search = relative.search;
|
||||||
result.query = relative.query;
|
result.query = relative.query;
|
||||||
srcPath = relPath;
|
srcPath = relPath;
|
||||||
|
@ -1538,7 +1538,21 @@ var relativeTests2 = [
|
|||||||
//changeing auth
|
//changeing auth
|
||||||
['http://diff:auth@www.example.com',
|
['http://diff:auth@www.example.com',
|
||||||
'http://asdf:qwer@www.example.com',
|
'http://asdf:qwer@www.example.com',
|
||||||
'http://diff:auth@www.example.com/']
|
'http://diff:auth@www.example.com/'],
|
||||||
|
|
||||||
|
// https://github.com/nodejs/node/issues/1435
|
||||||
|
['https://another.host.com/',
|
||||||
|
'https://user:password@example.org/',
|
||||||
|
'https://another.host.com/'],
|
||||||
|
['//another.host.com/',
|
||||||
|
'https://user:password@example.org/',
|
||||||
|
'https://another.host.com/'],
|
||||||
|
['http://another.host.com/',
|
||||||
|
'https://user:password@example.org/',
|
||||||
|
'http://another.host.com/'],
|
||||||
|
['mailto:another.host.com',
|
||||||
|
'mailto:user@example.org',
|
||||||
|
'mailto:another.host.com'],
|
||||||
];
|
];
|
||||||
relativeTests2.forEach(function(relativeTest) {
|
relativeTests2.forEach(function(relativeTest) {
|
||||||
const a = url.resolve(relativeTest[1], relativeTest[0]);
|
const a = url.resolve(relativeTest[1], relativeTest[0]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user