@@ -727,6 +727,25 @@ describe('yargs-parser', function () {
727727
728728 argv . error . message . should . equal ( 'someone set us up the bomb' )
729729 } )
730+
731+ it ( 'should not pollute the prototype' , function ( ) {
732+ const argv = parser ( [ '--foo' , 'bar' ] , {
733+ alias : {
734+ z : 'zoom'
735+ } ,
736+ default : {
737+ settings : jsonPath
738+ } ,
739+ config : 'settings'
740+ } )
741+
742+ argv . should . have . property ( 'herp' , 'derp' )
743+ argv . should . have . property ( 'zoom' , 55 )
744+ argv . should . have . property ( 'foo' ) . and . deep . equal ( 'bar' )
745+
746+ expect ( { } . bbb ) . to . equal ( undefined )
747+ expect ( { } . aaa ) . to . equal ( undefined )
748+ } )
730749 } )
731750
732751 describe ( 'config objects' , function ( ) {
@@ -974,6 +993,13 @@ describe('yargs-parser', function () {
974993 argv . f . foo . should . eql ( 99 )
975994 argv . f . bar . should . eql ( true )
976995 } )
996+
997+ it ( 'should not pollute the prototype' , function ( ) {
998+ parser ( [ '-f.__proto__.foo' , '99' , '-x.y.__proto__.bar' , '100' , '--__proto__' , '200' ] )
999+ Object . keys ( { } . __proto__ ) . length . should . equal ( 0 ) // eslint-disable-line
1000+ expect ( { } . foo ) . to . equal ( undefined )
1001+ expect ( { } . bar ) . to . equal ( undefined )
1002+ } )
9771003 } )
9781004
9791005 it ( 'should set boolean and alias using explicit true' , function ( ) {
@@ -3702,4 +3728,24 @@ describe('yargs-parser', function () {
37023728 argv . _ . should . eql ( [ 101 , 102 ] )
37033729 } )
37043730 } )
3731+
3732+ it ( 'should replace the key __proto__ with the key ___proto___' , function ( ) {
3733+ const argv = parser ( [ '-f.__proto__.foo' , '99' , '-x.y.__proto__.bar' , '100' , '--__proto__' , '200' ] )
3734+ argv . should . eql ( {
3735+ _ : [ ] ,
3736+ ___proto___ : 200 ,
3737+ f : {
3738+ ___proto___ : {
3739+ foo : 99
3740+ }
3741+ } ,
3742+ x : {
3743+ y : {
3744+ ___proto___ : {
3745+ bar : 100
3746+ }
3747+ }
3748+ }
3749+ } )
3750+ } )
37053751} )
0 commit comments