@@ -5,32 +5,46 @@ import deepmerge from './deepmerge';
55describe ( 'deepmerge' , ( ) => {
66 // https://snyk.io/blog/after-three-years-of-silence-a-new-jquery-prototype-pollution-vulnerability-emerges-once-again/
77 it ( 'should not be subject to prototype pollution via __proto__' , ( ) => {
8- deepmerge ( { } , JSON . parse ( '{ "myProperty": "a", "__proto__" : { "isAdmin" : true } }' ) , {
9- clone : false ,
10- } ) ;
8+ const result = deepmerge (
9+ { } ,
10+ JSON . parse ( '{ "myProperty": "a", "__proto__" : { "isAdmin" : true } }' ) ,
11+ {
12+ clone : false ,
13+ } ,
14+ ) ;
1115
16+ // @ts -expect-error __proto__ is not on this object type
17+ // eslint-disable-next-line no-proto
18+ expect ( result . __proto__ ) . to . have . property ( 'isAdmin' ) ;
1219 expect ( { } ) . not . to . have . property ( 'isAdmin' ) ;
1320 } ) ;
1421
1522 // https://cwe.mitre.org/data/definitions/915.html
1623 it ( 'should not be subject to prototype pollution via constructor' , ( ) => {
17- deepmerge (
24+ const result = deepmerge (
1825 { } ,
1926 JSON . parse ( '{ "myProperty": "a", "constructor" : { "prototype": { "isAdmin" : true } } }' ) ,
2027 {
2128 clone : true ,
2229 } ,
2330 ) ;
2431
32+ expect ( result . constructor . prototype ) . to . have . property ( 'isAdmin' ) ;
2533 expect ( { } ) . not . to . have . property ( 'isAdmin' ) ;
2634 } ) ;
2735
2836 // https://cwe.mitre.org/data/definitions/915.html
2937 it ( 'should not be subject to prototype pollution via prototype' , ( ) => {
30- deepmerge ( { } , JSON . parse ( '{ "myProperty": "a", "prototype": { "isAdmin" : true } }' ) , {
31- clone : false ,
32- } ) ;
38+ const result = deepmerge (
39+ { } ,
40+ JSON . parse ( '{ "myProperty": "a", "prototype": { "isAdmin" : true } }' ) ,
41+ {
42+ clone : false ,
43+ } ,
44+ ) ;
3345
46+ // @ts -expect-error prototype is not on this object type
47+ expect ( result . prototype ) . to . have . property ( 'isAdmin' ) ;
3448 expect ( { } ) . not . to . have . property ( 'isAdmin' ) ;
3549 } ) ;
3650
@@ -44,7 +58,7 @@ describe('deepmerge', () => {
4458 // eslint-disable-next-line no-proto
4559 expect ( result . __proto__ ) . to . have . property ( 'isAdmin' ) ;
4660 expect ( { } ) . not . to . have . property ( 'isAdmin' ) ;
47- } )
61+ } ) ;
4862
4963 it ( 'should merge objects across realms' , function test ( ) {
5064 if ( ! / j s d o m / . test ( window . navigator . userAgent ) ) {
0 commit comments