File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ class Y18N {
4747 this . fallbackToLanguage = typeof opts . fallbackToLanguage === 'boolean' ? opts . fallbackToLanguage : true
4848
4949 // internal stuff.
50- this . cache = { }
50+ this . cache = Object . create ( null )
5151 this . writeQueue = [ ]
5252 }
5353
Original file line number Diff line number Diff line change @@ -351,6 +351,24 @@ describe('y18n', function () {
351351 } )
352352 } )
353353
354+ // See: https://github.com/yargs/y18n/issues/96,
355+ // https://github.com/yargs/y18n/pull/107
356+ describe ( 'prototype pollution' , ( ) => {
357+ it ( 'does not pollute prototype, with __proto__ locale' , ( ) => {
358+ const y = y18n ( )
359+ y . setLocale ( '__proto__' )
360+ y . updateLocale ( { polluted : '👽' } )
361+ y . __ ( 'polluted' ) . should . equal ( '👽' )
362+ ; ( typeof polluted ) . should . equal ( 'undefined' )
363+ } )
364+
365+ it ( 'does not pollute prototype, when __ is used with __proto__ locale' , ( ) => {
366+ const __ = y18n ( { locale : '__proto__' } ) . __
367+ __ ( 'hello' )
368+ ; ( typeof { } . hello ) . should . equal ( 'undefined' )
369+ } )
370+ } )
371+
354372 after ( function ( ) {
355373 rimraf . sync ( './test/locales/fr.json' )
356374 } )
You can’t perform that action at this time.
0 commit comments