Aurelia-Validation implementation question


Hello, I recently upgraded to “aurelia-validation”: “^1.1.3”, and am encountering an error when there are zero rules.

I’ve tracked it down basically to this code:

StandardValidator.prototype.validate = function (object, propertyName, rules) {
    // rules specified?
    if (!rules) {
        // no. attempt to locate the rules.
        rules = Rules.get(object);  <== This line here
    // any rules?
    if (!rules) {
        return Promise.resolve([]);
    return this.validateRuleSequence(object, propertyName, rules, 0, []);

For one of my properties, the line I highlighted is returning an array, but that array is empty. Trouble is, the call to validateRuleSequence wants to make use of the first rule in the array, w/out actually checking that the array contains anything. So I get an error.

I’m thinking the second rule check should be
if (!rules || rules.length === 0) {

In the mean time, is there a workaround?


You can patch the function when bootstrapping your app until the issue is fixed - just copy and paste the code you’ve found, and edit as needed