File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ class Y18N {
47
47
this . fallbackToLanguage = typeof opts . fallbackToLanguage === 'boolean' ? opts . fallbackToLanguage : true
48
48
49
49
// internal stuff.
50
- this . cache = { }
50
+ this . cache = Object . create ( null )
51
51
this . writeQueue = [ ]
52
52
}
53
53
Original file line number Diff line number Diff line change @@ -351,6 +351,24 @@ describe('y18n', function () {
351
351
} )
352
352
} )
353
353
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
+
354
372
after ( function ( ) {
355
373
rimraf . sync ( './test/locales/fr.json' )
356
374
} )
You can’t perform that action at this time.
0 commit comments