@@ -476,6 +476,66 @@ test('parse()', function (t) {
476
476
st . end ( ) ;
477
477
} ) ;
478
478
479
+ t . test ( 'dunder proto is ignored' , function ( st ) {
480
+ var payload = 'categories[__proto__]=login&categories[__proto__]&categories[length]=42' ;
481
+ var result = qs . parse ( payload , { allowPrototypes : true } ) ;
482
+
483
+ st . deepEqual (
484
+ result ,
485
+ {
486
+ categories : {
487
+ length : '42'
488
+ }
489
+ } ,
490
+ 'silent [[Prototype]] payload'
491
+ ) ;
492
+
493
+ var plainResult = qs . parse ( payload , { allowPrototypes : true , plainObjects : true } ) ;
494
+
495
+ st . deepEqual (
496
+ plainResult ,
497
+ {
498
+ __proto__ : null ,
499
+ categories : {
500
+ __proto__ : null ,
501
+ length : '42'
502
+ }
503
+ } ,
504
+ 'silent [[Prototype]] payload: plain objects'
505
+ ) ;
506
+
507
+ var query = qs . parse ( 'categories[__proto__]=cats&categories[__proto__]=dogs&categories[some][json]=toInject' , { allowPrototypes : true } ) ;
508
+
509
+ st . notOk ( Array . isArray ( query . categories ) , 'is not an array' ) ;
510
+ st . notOk ( query . categories instanceof Array , 'is not instanceof an array' ) ;
511
+ st . deepEqual ( query . categories , { some : { json : 'toInject' } } ) ;
512
+ st . equal ( JSON . stringify ( query . categories ) , '{"some":{"json":"toInject"}}' , 'stringifies as a non-array' ) ;
513
+
514
+ st . deepEqual (
515
+ qs . parse ( 'foo[__proto__][hidden]=value&foo[bar]=stuffs' , { allowPrototypes : true } ) ,
516
+ {
517
+ foo : {
518
+ bar : 'stuffs'
519
+ }
520
+ } ,
521
+ 'hidden values'
522
+ ) ;
523
+
524
+ st . deepEqual (
525
+ qs . parse ( 'foo[__proto__][hidden]=value&foo[bar]=stuffs' , { allowPrototypes : true , plainObjects : true } ) ,
526
+ {
527
+ __proto__ : null ,
528
+ foo : {
529
+ __proto__ : null ,
530
+ bar : 'stuffs'
531
+ }
532
+ } ,
533
+ 'hidden values: plain objects'
534
+ ) ;
535
+
536
+ st . end ( ) ;
537
+ } ) ;
538
+
479
539
t . test ( 'can return null objects' , { skip : ! Object . create } , function ( st ) {
480
540
var expected = Object . create ( null ) ;
481
541
expected . a = Object . create ( null ) ;
0 commit comments