Skip to content

Commit

Permalink
Merge pull request #52 from bjnortier/required-property-with-zero-val…
Browse files Browse the repository at this point in the history
…ue-generates-error

Fix required properties with zero value errors.
  • Loading branch information
František Hába committed Feb 4, 2013
2 parents 7410d02 + 8812353 commit dc0de36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/engines/json/getProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
Validation.prototype.getProperty = function(property, source) {
if (source) {
return (source[property]) ? source[property] : undefined;
return (source[property] !== undefined) ? source[property] : undefined;
} else {
return undefined;
}
Expand Down
7 changes: 6 additions & 1 deletion tests/json/attributes/required/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ suite('JSON/Attribute/required#objects', function() {
},
surname: {
required: true
},
age: {
required: true,
type: 'number'
}
}
}
Expand All @@ -41,7 +45,8 @@ suite('JSON/Attribute/required#objects', function() {
jsonSchemaValidator.validate({
user: {
name: 'František',
surname: 'Hába'
surname: 'Hába',
age: 0,
}
}, schema, function(error) {
count += 1;
Expand Down

0 comments on commit dc0de36

Please sign in to comment.