@@ -7,14 +7,14 @@ function Cache(maxSize) {
77 this . _maxSize = maxSize
88 this . clear ( )
99}
10- Cache . prototype . clear = function ( ) {
10+ Cache . prototype . clear = function ( ) {
1111 this . _size = 0
1212 this . _values = Object . create ( null )
1313}
14- Cache . prototype . get = function ( key ) {
14+ Cache . prototype . get = function ( key ) {
1515 return this . _values [ key ]
1616}
17- Cache . prototype . set = function ( key , value ) {
17+ Cache . prototype . set = function ( key , value ) {
1818 this . _size >= this . _maxSize && this . clear ( )
1919 if ( ! ( key in this . _values ) ) this . _size ++
2020
@@ -41,23 +41,34 @@ module.exports = {
4141
4242 normalizePath : normalizePath ,
4343
44- setter : function ( path ) {
44+ setter : function ( path ) {
4545 var parts = normalizePath ( path )
4646
4747 return (
4848 setCache . get ( path ) ||
49- setCache . set ( path , function setter ( data , value ) {
50- var index = 0 ,
51- len = parts . length
49+ setCache . set ( path , function setter ( obj , value ) {
50+ var index = 0
51+ var len = parts . length
52+ var data = obj
53+
5254 while ( index < len - 1 ) {
55+ let part = parts [ index ]
56+ if (
57+ part === '__proto__' ||
58+ part === 'constructor' ||
59+ part === 'prototype'
60+ ) {
61+ return obj
62+ }
63+
5364 data = data [ parts [ index ++ ] ]
5465 }
5566 data [ parts [ index ] ] = value
5667 } )
5768 )
5869 } ,
5970
60- getter : function ( path , safe ) {
71+ getter : function ( path , safe ) {
6172 var parts = normalizePath ( path )
6273 return (
6374 getCache . get ( path ) ||
@@ -73,8 +84,8 @@ module.exports = {
7384 )
7485 } ,
7586
76- join : function ( segments ) {
77- return segments . reduce ( function ( path , part ) {
87+ join : function ( segments ) {
88+ return segments . reduce ( function ( path , part ) {
7889 return (
7990 path +
8091 ( isQuoted ( part ) || DIGIT_REGEX . test ( part )
@@ -84,17 +95,17 @@ module.exports = {
8495 } , '' )
8596 } ,
8697
87- forEach : function ( path , cb , thisArg ) {
98+ forEach : function ( path , cb , thisArg ) {
8899 forEach ( Array . isArray ( path ) ? path : split ( path ) , cb , thisArg )
89- }
100+ } ,
90101}
91102
92103function normalizePath ( path ) {
93104 return (
94105 pathCache . get ( path ) ||
95106 pathCache . set (
96107 path ,
97- split ( path ) . map ( function ( part ) {
108+ split ( path ) . map ( function ( part ) {
98109 return part . replace ( CLEAN_QUOTES_REGEX , '$2' )
99110 } )
100111 )
0 commit comments