@@ -632,6 +632,66 @@ test('parse()', function (t) {
632
632
st . end ( ) ;
633
633
} ) ;
634
634
635
+ t . test ( 'dunder proto is ignored' , function ( st ) {
636
+ var payload = 'categories[__proto__]=login&categories[__proto__]&categories[length]=42' ;
637
+ var result = qs . parse ( payload , { allowPrototypes : true } ) ;
638
+
639
+ st . deepEqual (
640
+ result ,
641
+ {
642
+ categories : {
643
+ length : '42'
644
+ }
645
+ } ,
646
+ 'silent [[Prototype]] payload'
647
+ ) ;
648
+
649
+ var plainResult = qs . parse ( payload , { allowPrototypes : true , plainObjects : true } ) ;
650
+
651
+ st . deepEqual (
652
+ plainResult ,
653
+ {
654
+ __proto__ : null ,
655
+ categories : {
656
+ __proto__ : null ,
657
+ length : '42'
658
+ }
659
+ } ,
660
+ 'silent [[Prototype]] payload: plain objects'
661
+ ) ;
662
+
663
+ var query = qs . parse ( 'categories[__proto__]=cats&categories[__proto__]=dogs&categories[some][json]=toInject' , { allowPrototypes : true } ) ;
664
+
665
+ st . notOk ( Array . isArray ( query . categories ) , 'is not an array' ) ;
666
+ st . notOk ( query . categories instanceof Array , 'is not instanceof an array' ) ;
667
+ st . deepEqual ( query . categories , { some : { json : 'toInject' } } ) ;
668
+ st . equal ( JSON . stringify ( query . categories ) , '{"some":{"json":"toInject"}}' , 'stringifies as a non-array' ) ;
669
+
670
+ st . deepEqual (
671
+ qs . parse ( 'foo[__proto__][hidden]=value&foo[bar]=stuffs' , { allowPrototypes : true } ) ,
672
+ {
673
+ foo : {
674
+ bar : 'stuffs'
675
+ }
676
+ } ,
677
+ 'hidden values'
678
+ ) ;
679
+
680
+ st . deepEqual (
681
+ qs . parse ( 'foo[__proto__][hidden]=value&foo[bar]=stuffs' , { allowPrototypes : true , plainObjects : true } ) ,
682
+ {
683
+ __proto__ : null ,
684
+ foo : {
685
+ __proto__ : null ,
686
+ bar : 'stuffs'
687
+ }
688
+ } ,
689
+ 'hidden values: plain objects'
690
+ ) ;
691
+
692
+ st . end ( ) ;
693
+ } ) ;
694
+
635
695
t . test ( 'can return null objects' , { skip : ! Object . create } , function ( st ) {
636
696
var expected = Object . create ( null ) ;
637
697
expected . a = Object . create ( null ) ;
0 commit comments