@@ -147,6 +147,19 @@ describe('Connection String', function () {
147
147
{ baz : 'bar' }
148
148
] ) ;
149
149
} ) ;
150
+
151
+ it ( 'should parse multiple and empty readPreferenceTags' , ( ) => {
152
+ const options = parseOptions (
153
+ 'mongodb://hostname?readPreferenceTags=bar:foo&readPreferenceTags=baz:bar&readPreferenceTags='
154
+ ) ;
155
+ expect ( options . readPreference . tags ) . to . deep . equal ( [ { bar : 'foo' } , { baz : 'bar' } , { } ] ) ;
156
+ } ) ;
157
+
158
+ it ( 'will set "__proto__" as own property on readPreferenceTag' , ( ) => {
159
+ const options = parseOptions ( 'mongodb://hostname?readPreferenceTags=__proto__:foo' ) ;
160
+ expect ( options . readPreference . tags ?. [ 0 ] ) . to . have . own . property ( '__proto__' , 'foo' ) ;
161
+ expect ( Object . getPrototypeOf ( options . readPreference . tags ?. [ 0 ] ) ) . to . be . null ;
162
+ } ) ;
150
163
} ) ;
151
164
152
165
context ( 'when the option is passed in the options object' , ( ) => {
@@ -156,12 +169,14 @@ describe('Connection String', function () {
156
169
} ) ;
157
170
expect ( options . readPreference . tags ) . to . deep . equal ( [ ] ) ;
158
171
} ) ;
172
+
159
173
it ( 'should parse a single readPreferenceTags object' , ( ) => {
160
174
const options = parseOptions ( 'mongodb://hostname?' , {
161
175
readPreferenceTags : [ { bar : 'foo' } ]
162
176
} ) ;
163
177
expect ( options . readPreference . tags ) . to . deep . equal ( [ { bar : 'foo' } ] ) ;
164
178
} ) ;
179
+
165
180
it ( 'should parse multiple readPreferenceTags' , ( ) => {
166
181
const options = parseOptions ( 'mongodb://hostname?' , {
167
182
readPreferenceTags : [ { bar : 'foo' } , { baz : 'bar' } ]
@@ -493,6 +508,18 @@ describe('Connection String', function () {
493
508
) ;
494
509
} ) ;
495
510
511
+ it ( 'throws an error for repeated options that can only appear once' , function ( ) {
512
+ // At the time of writing, readPreferenceTags is the only options that can be repeated
513
+ let thrownError ;
514
+ try {
515
+ parseOptions ( 'mongodb://localhost/?compressors=zstd&compressors=zstd' ) ;
516
+ } catch ( error ) {
517
+ thrownError = error ;
518
+ }
519
+ expect ( thrownError ) . to . be . instanceOf ( MongoInvalidArgumentError ) ;
520
+ expect ( thrownError . message ) . to . match ( / c a n n o t a p p e a r m o r e t h a n o n c e / ) ;
521
+ } ) ;
522
+
496
523
it ( 'should validate authMechanism' , function ( ) {
497
524
expect ( ( ) => parseOptions ( 'mongodb://localhost/?authMechanism=DOGS' ) ) . to . throw (
498
525
MongoParseError ,
0 commit comments