@@ -64,6 +64,9 @@ exports.get = function(path, o, special, map) {
64
64
65
65
for ( var i = 0 ; i < parts . length ; ++ i ) {
66
66
part = parts [ i ] ;
67
+ if ( typeof parts [ i ] !== 'string' && typeof parts [ i ] !== 'number' ) {
68
+ throw new TypeError ( 'Each segment of path to `get()` must be a string or number, got ' + typeof parts [ i ] ) ;
69
+ }
67
70
68
71
if ( Array . isArray ( obj ) && ! / ^ \d + $ / . test ( part ) ) {
69
72
// reading a property from the array items
@@ -112,6 +115,9 @@ exports.has = function(path, o) {
112
115
var len = parts . length ;
113
116
var cur = o ;
114
117
for ( var i = 0 ; i < len ; ++ i ) {
118
+ if ( typeof parts [ i ] !== 'string' && typeof parts [ i ] !== 'number' ) {
119
+ throw new TypeError ( 'Each segment of path to `has()` must be a string or number, got ' + typeof parts [ i ] ) ;
120
+ }
115
121
if ( cur == null || typeof cur !== 'object' || ! ( parts [ i ] in cur ) ) {
116
122
return false ;
117
123
}
@@ -143,6 +149,9 @@ exports.unset = function(path, o) {
143
149
if ( cur == null || typeof cur !== 'object' || ! ( parts [ i ] in cur ) ) {
144
150
return false ;
145
151
}
152
+ if ( typeof parts [ i ] !== 'string' && typeof parts [ i ] !== 'number' ) {
153
+ throw new TypeError ( 'Each segment of path to `unset()` must be a string or number, got ' + typeof parts [ i ] ) ;
154
+ }
146
155
// Disallow any updates to __proto__ or special properties.
147
156
if ( ignoreProperties . indexOf ( parts [ i ] ) !== - 1 ) {
148
157
return false ;
@@ -193,6 +202,9 @@ exports.set = function(path, val, o, special, map, _copying) {
193
202
if ( null == o ) return ;
194
203
195
204
for ( var i = 0 ; i < parts . length ; ++ i ) {
205
+ if ( typeof parts [ i ] !== 'string' && typeof parts [ i ] !== 'number' ) {
206
+ throw new TypeError ( 'Each segment of path to `set()` must be a string or number, got ' + typeof parts [ i ] ) ;
207
+ }
196
208
// Silently ignore any updates to `__proto__`, these are potentially
197
209
// dangerous if using mpath with unsanitized data.
198
210
if ( ignoreProperties . indexOf ( parts [ i ] ) !== - 1 ) {
0 commit comments