Browse Source

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

Fixes: https://github.com/nodejs/node/issues/8165

PR-URL: https://github.com/nodejs/node/pull/8215
Reviewed-By: James M Snell <jasnell@gmail.com>
v7.x
Ilkka Myller 8 years ago
committed by James M Snell
parent
commit
51f96dfcfc
  1. 4
      lib/url.js
  2. 3
      test/parallel/test-url.js

4
lib/url.js

@ -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;

3
test/parallel/test-url.js

@ -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]);

Loading…
Cancel
Save