File tree 3 files changed +20
-2
lines changed
3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ function Y18N (opts) {
11
11
this . fallbackToLanguage = typeof opts . fallbackToLanguage === 'boolean' ? opts . fallbackToLanguage : true
12
12
13
13
// internal stuff.
14
- this . cache = { }
14
+ this . cache = Object . create ( null )
15
15
this . writeQueue = [ ]
16
16
}
17
17
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " y18n" ,
3
- "version" : " 4.0.0 " ,
3
+ "version" : " 4.0.1 " ,
4
4
"description" : " the bare-bones internationalization library used by yargs" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change @@ -352,6 +352,24 @@ describe('y18n', function () {
352
352
} )
353
353
} )
354
354
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
+
355
373
after ( function ( ) {
356
374
rimraf . sync ( './test/locales/fr.json' )
357
375
} )
You can’t perform that action at this time.
0 commit comments