@@ -9,6 +9,7 @@ import { object as locale } from './locale.js';
9
9
import sortFields from './util/sortFields' ;
10
10
import sortByKeyOrder from './util/sortByKeyOrder' ;
11
11
import inherits from './util/inherits' ;
12
+ import makePath from './util/makePath' ;
12
13
import runValidations , { propagateErrors } from './util/runValidations' ;
13
14
14
15
let isObject = obj => Object . prototype . toString . call ( obj ) === '[object Object]' ;
@@ -76,8 +77,8 @@ inherits(ObjectSchema, MixedSchema, {
76
77
return isObject ( value ) || typeof value === 'function' ;
77
78
} ,
78
79
79
- _cast ( _value , opts = { } ) {
80
- var value = MixedSchema . prototype . _cast . call ( this , _value , opts )
80
+ _cast ( _value , options = { } ) {
81
+ var value = MixedSchema . prototype . _cast . call ( this , _value , options )
81
82
82
83
//should ignore nulls here
83
84
if ( value === undefined )
@@ -87,18 +88,18 @@ inherits(ObjectSchema, MixedSchema, {
87
88
return value ;
88
89
89
90
var fields = this . fields
90
- , strip = this . _option ( 'stripUnknown' , opts ) === true
91
+ , strip = this . _option ( 'stripUnknown' , options ) === true
91
92
, extra = Object . keys ( value ) . filter ( v => this . _nodes . indexOf ( v ) === - 1 )
92
93
, props = this . _nodes . concat ( extra ) ;
93
94
94
95
let innerOptions = {
95
- ...opts ,
96
+ ...options ,
96
97
parent : { } , // is filled during the transform below
97
98
__validating : false ,
98
99
} ;
99
100
100
101
value = transform ( props , ( obj , prop ) => {
101
- let field = fields [ prop ]
102
+ let field = fields [ prop ] ;
102
103
let exists = has ( value , prop ) ;
103
104
104
105
if ( field ) {
@@ -108,7 +109,10 @@ inherits(ObjectSchema, MixedSchema, {
108
109
if ( field . _strip === true )
109
110
return
110
111
111
- fieldValue = ! opts . __validating || ! strict
112
+ // should be safe to mutate since this is fired in sequence
113
+ innerOptions . path = makePath `${ options . path } .${ prop } ` ;
114
+
115
+ fieldValue = ! options . __validating || ! strict
112
116
? field . cast ( value [ prop ] , innerOptions )
113
117
: value [ prop ]
114
118
@@ -142,7 +146,7 @@ inherits(ObjectSchema, MixedSchema, {
142
146
}
143
147
144
148
let validations = this . _nodes . map ( key => {
145
- var path = ( opts . path ? ( opts . path + '.' ) : '' ) + key
149
+ var path = makePath ` ${ opts . path } . ${ key } `
146
150
, field = this . fields [ key ]
147
151
, innerOptions = { ...opts , path, parent : value } ;
148
152
0 commit comments