11'use strict' ;
22
3-
43/* !
54 * Chai - pathval utility
65 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
@@ -77,6 +76,13 @@ function parsePath(path) {
7776 var str = path . replace ( / ( [ ^ \\ ] ) \[ / g, '$1.[' ) ;
7877 var parts = str . match ( / ( \\ \. | [ ^ . ] + ?) + / g) ;
7978 return parts . map ( function mapMatches ( value ) {
79+ if (
80+ value === 'constructor' ||
81+ value === '__proto__' ||
82+ value === 'prototype'
83+ ) {
84+ return { } ;
85+ }
8086 var regexp = / ^ \[ ( \d + ) \] $ / ;
8187 var mArr = regexp . exec ( value ) ;
8288 var parsed = null ;
@@ -108,7 +114,7 @@ function parsePath(path) {
108114function internalGetPathValue ( obj , parsed , pathDepth ) {
109115 var temporaryValue = obj ;
110116 var res = null ;
111- pathDepth = ( typeof pathDepth === 'undefined' ? parsed . length : pathDepth ) ;
117+ pathDepth = typeof pathDepth === 'undefined' ? parsed . length : pathDepth ;
112118
113119 for ( var i = 0 ; i < pathDepth ; i ++ ) {
114120 var part = parsed [ i ] ;
@@ -119,7 +125,7 @@ function internalGetPathValue(obj, parsed, pathDepth) {
119125 temporaryValue = temporaryValue [ part . p ] ;
120126 }
121127
122- if ( i === ( pathDepth - 1 ) ) {
128+ if ( i === pathDepth - 1 ) {
123129 res = temporaryValue ;
124130 }
125131 }
@@ -153,7 +159,7 @@ function internalSetPathValue(obj, val, parsed) {
153159 part = parsed [ i ] ;
154160
155161 // 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 ) {
157163 propName = typeof part . p === 'undefined' ? part . i : part . p ;
158164 // Now we set the property with the name held by 'propName' on object with the desired val
159165 tempObj [ propName ] = val ;
@@ -200,7 +206,10 @@ function getPathInfo(obj, path) {
200206 var parsed = parsePath ( path ) ;
201207 var last = parsed [ parsed . length - 1 ] ;
202208 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 ,
204213 name : last . p || last . i ,
205214 value : internalGetPathValue ( obj , parsed ) ,
206215 } ;
0 commit comments