Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: drop auth in url.resolve() if host changes #1480

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ Url.prototype.resolveObject = function(relative) {
if (relative.protocol) {
relative.hostname = null;
relative.port = null;
result.auth = null;
if (relative.host) {
if (relPath[0] === '') relPath[0] = relative.host;
else relPath.unshift(relative.host);
Expand All @@ -564,10 +565,14 @@ Url.prototype.resolveObject = function(relative) {

if (isRelAbs) {
// it's absolute.
result.host = (relative.host || relative.host === '') ?
relative.host : result.host;
result.hostname = (relative.hostname || relative.hostname === '') ?
relative.hostname : result.hostname;
if (relative.host || relative.host === '') {
result.host = relative.host;
result.auth = null;
}
if (relative.hostname || relative.hostname === '') {
result.hostname = relative.hostname;
result.auth = null;
}
result.search = relative.search;
result.query = relative.query;
srcPath = relPath;
Expand Down
16 changes: 15 additions & 1 deletion test/parallel/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,21 @@ var relativeTests2 = [
//changeing auth
['http://diff:[email protected]',
'http://asdf:[email protected]',
'http://diff:[email protected]/']
'http://diff:[email protected]/'],

// https://github.com/iojs/io.js/issues/1435
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be changed to point to the nodejs/node repo

Copy link
Member

@jasnell jasnell Apr 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I was going to change that upon landing (although, I kinda like that it still points to iojs, lol)

['https://another.host.com/',
'https://user:[email protected]/',
'https://another.host.com/'],
['//another.host.com/',
'https://user:[email protected]/',
'https://another.host.com/'],
['http://another.host.com/',
'https://user:[email protected]/',
'http://another.host.com/'],
['mailto:another.host.com',
'mailto:[email protected]',
'mailto:another.host.com'],
];
relativeTests2.forEach(function(relativeTest) {
var a = url.resolve(relativeTest[1], relativeTest[0]),
Expand Down