File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,21 @@ ExportAdapter.prototype.connect = function() {
34
34
return this . connectionPromise ;
35
35
}
36
36
37
+ //http://regexr.com/3cn6m
38
+ if ( ! this . mongoURI . match ( / ^ m o n g o d b : \/ \/ ( ( .+ ) : ( .+ ) @ ) ? ( [ ^ : @ ] + ) : ( [ ^ : ] + ) \/ ( .+ ?) $ / gm) ) {
39
+ throw new Error ( "Invalid mongoURI: " + this . mongoURI )
40
+ }
41
+ var usernameStart = this . mongoURI . indexOf ( '://' ) + 3 ;
42
+ var lastAtIndex = this . mongoURI . lastIndexOf ( '@' ) ;
43
+ var encodedMongoURI = this . mongoURI ;
44
+ var split = null ;
45
+ if ( lastAtIndex > 0 ) {
46
+ split = this . mongoURI . slice ( usernameStart , lastAtIndex ) . split ( ':' ) ;
47
+ encodedMongoURI = this . mongoURI . slice ( 0 , usernameStart ) + encodeURIComponent ( split [ 0 ] ) + ':' + encodeURIComponent ( split [ 1 ] ) + this . mongoURI . slice ( lastAtIndex ) ;
48
+ }
49
+
37
50
this . connectionPromise = Promise . resolve ( ) . then ( ( ) => {
38
- return MongoClient . connect ( this . mongoURI ) ;
51
+ return MongoClient . connect ( encodedMongoURI , { uri_decode_auth : true } ) ;
39
52
} ) . then ( ( db ) => {
40
53
this . db = db ;
41
54
} ) ;
You can’t perform that action at this time.
0 commit comments