Skip to content

Bug in alias for enum.(posible solution added) #130

@joolfe

Description

@joolfe

Hi,

I have found a little bug using alias, to reproduce just:

const v = new Validator();

v.alias('algList', { type: "array", items: "string", enum: ['RS256' , 'PS256'] });

const toValidate = {
    request_object_signing_alg_values_supported: ['RS256S']
}

const schema = { 
     request_object_signing_alg_values_supported: "algList"
};

const check = v.compile(schema);

console.log("First:", check(toValidate));

Im getting the error

/node_modules/fastest-validator/lib/rules/array.js:70
                                        ${this.makeError({ type: "arrayEnum", expected: "\"" + schema.enum.join(", ") + "\"", actual: "value[i]", messages })}
                                                                                                           ^
TypeError: schema.enum.join is not a function

After debug a bit i have seen that schema has the value

{
  type: 'array',
  items: 'string',
  enum: { '0': 'RS256', '1': 'PS256' }
}

The enum field has been modified for an Object, the problem is in /fastest-validator/lib/helpers/deep-extend.js file because is checking object just with typeof source[property] === "object" and this is also true for an array.

As possible solution i purpose to replace thia check with a source[property].constructor !== Object or add an additional check in the same if like !Array.isArray(source[property]) &&

Best Regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions