Skip to content

Commit eabf7e1

Browse files
jarvelovgchauvet
authored andcommitted
Fix bug with forbidUndefinedVariables (#62)
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.
1 parent 2f820d5 commit eabf7e1

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/validation.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,23 @@ module.exports.process = function (validationModel, req, options) {
176176
keys.splice(index, 1);
177177
}
178178
});
179-
if (options.forbidUndefinedVariables === true) {
180-
keys.forEach(function(key) {
181-
addError(_createError(realScope, key, { name: "undefinedVariable" }));
182-
});
183-
}
179+
if (options.forbidUndefinedVariables === true) {
180+
keys.forEach(function(key) {
181+
var invalid = true;
182+
183+
// check if key exist in some other scope in the validationModel
184+
_.each(validationModel, function (validationModelScope) {
185+
if (key in validationModelScope) {
186+
invalid = false;
187+
}
188+
});
189+
190+
// flag key as undefined if it didn't show up in another scope
191+
if (invalid) {
192+
addError(_createError(realScope, key, { name: "undefinedVariable" }));
193+
}
194+
});
195+
}
184196
}
185197
});
186198
return errors;

0 commit comments

Comments
 (0)