Skip to content

noDefaults behaviour with any.empty() #1095

@anthochamp

Description

@anthochamp

Context

  • node version: 6.5.0
  • joi version: 10.2.0
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information: -

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

const schema = Joi.number().empty(5).default(5);

const res1 = Joi.validate({ Test: 5 }, { Test: schema }, { noDefaults: false });
const res2 = Joi.validate({ Test: 5 }, { Test: schema }, { noDefaults: true });

Which result you had ?

res1.Test === 5
res2.Test === 5

What did you expect ?

res1.Test === 5
res2.Test === undefined

Hello ! i'm able to it work by changing L450 of lib/any.js from :

else if (options.noDefaults) {
  finalValue = originalValue;
}

to:

else if (options.noDefaults) {
  finalValue = value;
}

not sure it didn't break something else in the process tho... ?

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