Skip to content

Commit

Permalink
Coerce if a coerce property is set and the instance property exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Nov 11, 2010
1 parent f664d58 commit f9ed902
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ var validate = exports._validate = function(/*Any*/instance,/*Object*/schema,/*B
if(value === undefined && propDef["default"]){
value = instance[i] = propDef["default"];
}
if(exports.coerce){
if(propDef.coerce && exports.coerce && i in instance){
value = instance[i] = exports.coerce(value, propDef);
}
checkProp(value,propDef,path,i);
Expand All @@ -201,7 +201,7 @@ var validate = exports._validate = function(/*Any*/instance,/*Object*/schema,/*B
}
value = instance[i];
if(additionalProp && (!(objTypeDef && typeof objTypeDef == 'object') || !(i in objTypeDef))){
if(exports.coerce){
if(additionalProp.coerce && exports.coerce){
value = instance[i] = exports.coerce(value, additionalProp);
}
checkProp(value,additionalProp,path,i);
Expand Down

0 comments on commit f9ed902

Please sign in to comment.