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