Skip to content

Commit

Permalink
Fix validation for arrays of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick committed Jul 10, 2014
1 parent 3167c53 commit dea5ce6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ function value(key, val, constants, ref, spec, errors) {
for (var i = 0; i < val.length; i++) {
var valspec = ref[spec.value]||spec.value;
if (typeof valspec === 'string') {
pass = validateNative(key + '[' + i + ']', val[i], valspec, errors) && pass;
if (spec.function && typeof val[i] === 'object') {
pass = value(key, val[i], constants, ref, ref.function, errors);
} else {
pass = validateNative(key + '[' + i + ']', val[i], valspec, errors) && pass;
}
} else {
pass = value(key + '[' + i + ']', val[i], constants, ref, valspec, errors) && pass;
}
Expand All @@ -107,7 +111,7 @@ function value(key, val, constants, ref, spec, errors) {
} else {
errors.push({
message: key + ': array expected, ' + typeof val + ' found',
line: val.__line__
line: val ? val.__line__ : null
});
return false;
}
Expand Down Expand Up @@ -189,7 +193,7 @@ function validateNative(key, val, spec, errors) {
if (type !== spec) {
errors.push({
message: key + ': ' + spec + ' expected, ' + (typeof val) + ' found',
line: val.__line__
line: val ? val.__line__ : null
});
return false;
} else {
Expand All @@ -208,4 +212,3 @@ function validateEnum(key, val, spec, errors) {
return true;
}
}

0 comments on commit dea5ce6

Please sign in to comment.