Skip to content

Commit

Permalink
Fix bug with forbidUndefinedVariables (#62)
Browse files Browse the repository at this point in the history
The forbidUndefinedVariables check wrongly flagged keys that existed in other scopes as undefined, this fix checks for the key in the other scopes of the validationModel before flagging it as undefined.
  • Loading branch information
jarvelov authored and gchauvet committed Nov 20, 2016
1 parent 2f820d5 commit eabf7e1
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,23 @@ module.exports.process = function (validationModel, req, options) {
keys.splice(index, 1);
}
});
if (options.forbidUndefinedVariables === true) {
keys.forEach(function(key) {
addError(_createError(realScope, key, { name: "undefinedVariable" }));
});
}
if (options.forbidUndefinedVariables === true) {
keys.forEach(function(key) {
var invalid = true;

// check if key exist in some other scope in the validationModel
_.each(validationModel, function (validationModelScope) {
if (key in validationModelScope) {
invalid = false;
}
});

// flag key as undefined if it didn't show up in another scope
if (invalid) {
addError(_createError(realScope, key, { name: "undefinedVariable" }));
}
});
}
}
});
return errors;
Expand Down

0 comments on commit eabf7e1

Please sign in to comment.