Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix required properties with zero value errors. #52

Merged
merged 1 commit into from

2 participants

@bjnortier

'required' properties that have a zero value generate an error when they should not. This is
due to if (source[property]) check in getProperty, instead of (source[property] !== undefined)

@bjnortier bjnortier Fix required properties with zero value errors.
'required' properties that have a zero value
generate an error when they should not. This is
due to if (source[property]) check in getProperty,
instead of (source[property] !== undefined)
8812353
@Baggz
Owner

Thanks, @bjnortier.

@Baggz Baggz closed this
@Baggz Baggz reopened this
@Baggz Baggz merged commit dc0de36 into from
@bjnortier

Thanks for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 4, 2013
  1. @bjnortier

    Fix required properties with zero value errors.

    bjnortier authored
    'required' properties that have a zero value
    generate an error when they should not. This is
    due to if (source[property]) check in getProperty,
    instead of (source[property] !== undefined)
This page is out of date. Refresh to see the latest.
View
2  src/engines/json/getProperty.js
@@ -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;
}
View
7 tests/json/attributes/required/objects.js
@@ -23,6 +23,10 @@ suite('JSON/Attribute/required#objects', function() {
},
surname: {
required: true
+ },
+ age: {
+ required: true,
+ type: 'number'
}
}
}
@@ -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;
Something went wrong with that request. Please try again.