This repository was archived by the owner on May 17, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -142,5 +142,7 @@ module.exports.getId = function(id) {
142
142
return id . toLowerCase ( )
143
143
. replace ( hostname . toLowerCase ( ) , 'localhost' )
144
144
. replace ( '127.0.0.1' , 'localhost' )
145
- . replace ( 'mongodb://' , '' ) ;
145
+ . replace ( 'mongodb://' , '' )
146
+ . replace ( / ^ [ ^ @ ] + @ / , '' )
147
+ . replace ( / \/ ? \? (?: \w + = [ ^ & ] + & ) * \w + = [ ^ & ] + $ / , '' ) ;
146
148
} ;
Original file line number Diff line number Diff line change @@ -23,6 +23,18 @@ describe('mongodb-instance-model', function() {
23
23
it ( 'should remove mongodb://' , function ( ) {
24
24
assert . equal ( Instance . getId ( 'mongodb://localhost:27017' ) , 'localhost:27017' ) ;
25
25
} ) ;
26
+ it ( 'should remove mongodb://user:pass@' , function ( ) {
27
+ assert . equal ( Instance . getId ( 'mongodb://matt:123@localhost:27017' ) , 'localhost:27017' ) ;
28
+ } ) ;
29
+ it ( 'should remove user:pass@' , function ( ) {
30
+ assert . equal ( Instance . getId ( 'matt:123@localhost:27017' ) , 'localhost:27017' ) ;
31
+ } ) ;
32
+ it ( 'should remove a trailing option' , function ( ) {
33
+ assert . equal ( Instance . getId ( 'localhost:27017/?option=thing' ) , 'localhost:27017' ) ;
34
+ } ) ;
35
+ it ( 'should remove many trailing options' , function ( ) {
36
+ assert . equal ( Instance . getId ( 'localhost:27017/?option=thing&otherThing=coolStuff&zombies=true' ) , 'localhost:27017' ) ;
37
+ } ) ;
26
38
it ( 'should substitute localhost for 127.0.0.1' , function ( ) {
27
39
assert . equal ( Instance . getId ( '127.0.0.1:27017' ) , 'localhost:27017' ) ;
28
40
} ) ;
You can’t perform that action at this time.
0 commit comments