Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix ‘Amanda 0.4.3 breaks validation of 'falsey' values’

  • Loading branch information...
commit 6368366958471be7657ae34f25767409a0d5ebd4 1 parent 78cc1b1
František Hába authored
4 src/engines/json/getProperty.js
View
@@ -1,12 +1,12 @@
/**
* GetProperty
*
- * @param {string} property
+ * @param {string} property
* @param {object} source
*/
Validation.prototype.getProperty = function(property, source) {
if (source) {
- return (source[property] !== undefined) ? source[property] : undefined;
+ return (isDefined(source[property])) ? source[property] : undefined;
} else {
return undefined;
}
40 tests/json/attributes/type/boolean.js
View
@@ -19,11 +19,20 @@ suite('JSON/Attribute/type#boolean', function() {
};
/**
+ * Schema
+ */
+ var schemaWithRequired = {
+ required: true,
+ type: 'boolean'
+ };
+
+ /**
* Validator
*/
var Validator = amanda('json');
test('should not return an error', function() {
+
[
true,
false
@@ -33,9 +42,21 @@ suite('JSON/Attribute/type#boolean', function() {
expect(error).to.not.be.ok();
});
});
+
+ [
+ true,
+ false
+ ].forEach(function(instance) {
+ Validator.validate(instance, schemaWithRequired, function(error) {
+ count += 1;
+ expect(error).to.not.be.ok();
+ });
+ });
+
});
test('should return an error', function() {
+
[
'Hello',
123,
@@ -48,10 +69,25 @@ suite('JSON/Attribute/type#boolean', function() {
expect(error).to.be.ok();
});
});
+
+ [
+ undefined,
+ 'Hello',
+ 123,
+ {},
+ [],
+ function() {}
+ ].forEach(function(instance) {
+ Validator.validate(instance, schemaWithRequired, function(error) {
+ count += 1;
+ expect(error).to.be.ok();
+ });
+ });
+
});
- test('should run 7 times', function() {
- expect(count).to.be.eql(7);
+ test('should run 15 times', function() {
+ expect(count).to.be.eql(15);
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.