diff --git a/ExportAdapter.js b/ExportAdapter.js index 89cb6c5900..db586d8348 100644 --- a/ExportAdapter.js +++ b/ExportAdapter.js @@ -34,8 +34,21 @@ ExportAdapter.prototype.connect = function() { 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 lastAtIndex = this.mongoURI.lastIndexOf('@'); + var encodedMongoURI = this.mongoURI; + 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; });