added regex to validate mongo uri and remove unused variables
This commit is contained in:
@@ -34,12 +34,14 @@ ExportAdapter.prototype.connect = function() {
|
|||||||
return this.connectionPromise;
|
return this.connectionPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//http://regexr.com/3cn6m
|
||||||
|
if (!this.mongoURI.match(/^mongodb:\/\/((.+):(.+)@)?([^:@]+):([^:]+)\/(.+?)$/gm)) {
|
||||||
|
throw new Error("Invalid mongoURI: " + this.mongoURI)
|
||||||
|
}
|
||||||
var usernameStart = this.mongoURI.indexOf('://') + 3;
|
var usernameStart = this.mongoURI.indexOf('://') + 3;
|
||||||
var lastAtIndex = this.mongoURI.lastIndexOf('@');
|
var lastAtIndex = this.mongoURI.lastIndexOf('@');
|
||||||
var encodedMongoURI = this.mongoURI;
|
var encodedMongoURI = this.mongoURI;
|
||||||
var username = null;
|
var split = null;
|
||||||
var password = null;
|
|
||||||
var split = null
|
|
||||||
if (lastAtIndex > 0) {
|
if (lastAtIndex > 0) {
|
||||||
split = this.mongoURI.slice(usernameStart, lastAtIndex).split(':');
|
split = this.mongoURI.slice(usernameStart, lastAtIndex).split(':');
|
||||||
encodedMongoURI = this.mongoURI.slice(0, usernameStart) + encodeURIComponent(split[0]) + ':' + encodeURIComponent(split[1]) + this.mongoURI.slice(lastAtIndex);
|
encodedMongoURI = this.mongoURI.slice(0, usernameStart) + encodeURIComponent(split[0]) + ':' + encodeURIComponent(split[1]) + this.mongoURI.slice(lastAtIndex);
|
||||||
|
|||||||
Reference in New Issue
Block a user