Skip to content

Using empty in items on sparse array allows undefined elements. #909

Closed
@nlindley

Description

@nlindley

Context

What are you trying to achieve or the steps to reproduce ?

When marking an array as sparse(false), and items() has a schema that uses empty(), there is no error.

const schema = Joi.array().items(Joi.object().empty({})).sparse(false);
const data = [{a: 1}, {}, {c: 3}];

schema.validate(data);

Which result you had ?

{ error: null, value: [{a: 1 }, undefined, { c: 3 }] }

What did you expect ?

{ error: 
   { [ValidationError: "value" must not be a sparse array]
     isJoi: true,
     name: 'ValidationError',
     details: [ [Object] ],
     _object: [ [Object], undefined, [Object] ],
     annotate: [Function] },
  value: [ { a: 1 }, undefined, { c: 3 } ] }

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions