Skip to content

Commit 97cf00b

Browse files
committed
added regex to validate mongo uri and remove unused variables
1 parent 6b91b98 commit 97cf00b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ExportAdapter.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ ExportAdapter.prototype.connect = function() {
3434
return this.connectionPromise;
3535
}
3636

37+
//http://regexr.com/3cn6m
38+
if (!this.mongoURI.match(/^mongodb:\/\/((.+):(.+)@)?([^:@]+):([^:]+)\/(.+?)$/gm)) {
39+
throw new Error("Invalid mongoURI: " + this.mongoURI)
40+
}
3741
var usernameStart = this.mongoURI.indexOf('://') + 3;
3842
var lastAtIndex = this.mongoURI.lastIndexOf('@');
3943
var encodedMongoURI = this.mongoURI;
40-
var username = null;
41-
var password = null;
42-
var split = null
44+
var split = null;
4345
if (lastAtIndex > 0) {
4446
split = this.mongoURI.slice(usernameStart, lastAtIndex).split(':');
4547
encodedMongoURI = this.mongoURI.slice(0, usernameStart) + encodeURIComponent(split[0]) + ':' + encodeURIComponent(split[1]) + this.mongoURI.slice(lastAtIndex);

0 commit comments

Comments
 (0)