Skip to content

Added encoding to user name and password #148

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

Merged
merged 3 commits into from
Feb 2, 2016
Merged
Changes from 1 commit
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: 12 additions & 1 deletion ExportAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,19 @@ ExportAdapter.prototype.connect = function() {
return this.connectionPromise;
}

var usernameStart = this.mongoURI.indexOf('://') + 3;
var lastAtIndex = this.mongoURI.lastIndexOf('@');
var encodedMongoURI = this.mongoURI;
var username = null;
var password = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

It does not look like username or password are used... and it looks like the database uri is being somewhat validated here, so how about we throw an error if it's not?

var split = null
if (lastAtIndex > 0) {
split = this.mongoURI.slice(usernameStart, lastAtIndex).split(':');
encodedMongoURI = this.mongoURI.slice(0, usernameStart) + encodeURIComponent(split[0]) + ':' + encodeURIComponent(split[1]) + this.mongoURI.slice(lastAtIndex);
}

this.connectionPromise = Promise.resolve().then(() => {
return MongoClient.connect(this.mongoURI);
return MongoClient.connect(encodedMongoURI, {uri_decode_auth:true});
}).then((db) => {
this.db = db;
});
Expand Down