Skip to content

Commit

Permalink
Corrected checks on defuault values
Browse files Browse the repository at this point in the history
  • Loading branch information
morphar committed Apr 22, 2015
1 parent bbbe946 commit 560d0e6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ ObjectSchema.prototype.runValidations = function(field, definition, testObject,
!definition.required &&
(!testObject || typeof testObject[field] === 'undefined')) {

if (definition.default) return definition.default;
if (typeof definition.default !== 'undefined') return definition.default;
else return;
}

Expand Down Expand Up @@ -194,7 +194,7 @@ ObjectSchema.prototype.runValidations = function(field, definition, testObject,
if (definition.filters) {
this.definitionFilters(field, definition, testObject, errors);
}
if (definition.default) {
if (typeof definition.default !== 'undefined') {
this.definitionDefault(field, definition, testObject, errors);
}

Expand Down Expand Up @@ -271,7 +271,7 @@ ObjectSchema.prototype.definitionFilters = function(field, definition, testObjec
*/
ObjectSchema.prototype.definitionDefault = function(field, definition, testObject, errors) {
/** If no value is found, even after running filters, set the default */
if (definition.default && typeof testObject[field] === 'undefined') {
if (typeof definition.default !== 'undefined' && typeof testObject[field] === 'undefined') {
testObject[field] = definition.default;
}
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "object-schema",
"version": "0.1.18",
"version": "0.1.19",
"description": "Object filter/schema for filtering, checking and validating javascript objects",
"keywords": [
"json",
Expand Down

0 comments on commit 560d0e6

Please sign in to comment.