File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed
Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ function Y18N (opts) {
1111 this . fallbackToLanguage = typeof opts . fallbackToLanguage === 'boolean' ? opts . fallbackToLanguage : true
1212
1313 // internal stuff.
14- this . cache = { }
14+ this . cache = Object . create ( null )
1515 this . writeQueue = [ ]
1616}
1717
Original file line number Diff line number Diff line change 11{
22 "name" : " y18n" ,
3- "version" : " 4.0.0 " ,
3+ "version" : " 4.0.1 " ,
44 "description" : " the bare-bones internationalization library used by yargs" ,
55 "main" : " index.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change @@ -352,6 +352,24 @@ describe('y18n', function () {
352352 } )
353353 } )
354354
355+ // See: https://github.com/yargs/y18n/issues/96,
356+ // https://github.com/yargs/y18n/pull/107
357+ describe ( 'prototype pollution' , ( ) => {
358+ it ( 'does not pollute prototype, with __proto__ locale' , ( ) => {
359+ const y = y18n ( )
360+ y . setLocale ( '__proto__' )
361+ y . updateLocale ( { polluted : '👽' } )
362+ y . __ ( 'polluted' ) . should . equal ( '👽' )
363+ ; ( typeof polluted ) . should . equal ( 'undefined' )
364+ } )
365+
366+ it ( 'does not pollute prototype, when __ is used with __proto__ locale' , ( ) => {
367+ const __ = y18n ( { locale : '__proto__' } ) . __
368+ __ ( 'hello' )
369+ ; ( typeof { } . hello ) . should . equal ( 'undefined' )
370+ } )
371+ } )
372+
355373 after ( function ( ) {
356374 rimraf . sync ( './test/locales/fr.json' )
357375 } )
You can’t perform that action at this time.
0 commit comments