1
1
'use strict' ;
2
2
3
-
4
3
/* !
5
4
* Chai - pathval utility
6
5
* Copyright(c) 2012-2014 Jake Luer <[email protected] >
@@ -77,6 +76,13 @@ function parsePath(path) {
77
76
var str = path . replace ( / ( [ ^ \\ ] ) \[ / g, '$1.[' ) ;
78
77
var parts = str . match ( / ( \\ \. | [ ^ . ] + ?) + / g) ;
79
78
return parts . map ( function mapMatches ( value ) {
79
+ if (
80
+ value === 'constructor' ||
81
+ value === '__proto__' ||
82
+ value === 'prototype'
83
+ ) {
84
+ return { } ;
85
+ }
80
86
var regexp = / ^ \[ ( \d + ) \] $ / ;
81
87
var mArr = regexp . exec ( value ) ;
82
88
var parsed = null ;
@@ -108,7 +114,7 @@ function parsePath(path) {
108
114
function internalGetPathValue ( obj , parsed , pathDepth ) {
109
115
var temporaryValue = obj ;
110
116
var res = null ;
111
- pathDepth = ( typeof pathDepth === 'undefined' ? parsed . length : pathDepth ) ;
117
+ pathDepth = typeof pathDepth === 'undefined' ? parsed . length : pathDepth ;
112
118
113
119
for ( var i = 0 ; i < pathDepth ; i ++ ) {
114
120
var part = parsed [ i ] ;
@@ -119,7 +125,7 @@ function internalGetPathValue(obj, parsed, pathDepth) {
119
125
temporaryValue = temporaryValue [ part . p ] ;
120
126
}
121
127
122
- if ( i === ( pathDepth - 1 ) ) {
128
+ if ( i === pathDepth - 1 ) {
123
129
res = temporaryValue ;
124
130
}
125
131
}
@@ -153,7 +159,7 @@ function internalSetPathValue(obj, val, parsed) {
153
159
part = parsed [ i ] ;
154
160
155
161
// If it's the last part of the path, we set the 'propName' value with the property name
156
- if ( i === ( pathDepth - 1 ) ) {
162
+ if ( i === pathDepth - 1 ) {
157
163
propName = typeof part . p === 'undefined' ? part . i : part . p ;
158
164
// Now we set the property with the name held by 'propName' on object with the desired val
159
165
tempObj [ propName ] = val ;
@@ -200,7 +206,10 @@ function getPathInfo(obj, path) {
200
206
var parsed = parsePath ( path ) ;
201
207
var last = parsed [ parsed . length - 1 ] ;
202
208
var info = {
203
- parent : parsed . length > 1 ? internalGetPathValue ( obj , parsed , parsed . length - 1 ) : obj ,
209
+ parent :
210
+ parsed . length > 1 ?
211
+ internalGetPathValue ( obj , parsed , parsed . length - 1 ) :
212
+ obj ,
204
213
name : last . p || last . i ,
205
214
value : internalGetPathValue ( obj , parsed ) ,
206
215
} ;
0 commit comments