Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noDefaults behaviour with any.empty() #1095

Closed
anthochamp opened this issue Feb 2, 2017 · 1 comment
Closed

noDefaults behaviour with any.empty() #1095

anthochamp opened this issue Feb 2, 2017 · 1 comment
Assignees
Labels
bug Bug or defect
Milestone

Comments

@anthochamp
Copy link

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... ?

@Marsup Marsup self-assigned this Feb 2, 2017
@Marsup Marsup added the bug Bug or defect label Feb 2, 2017
@Marsup Marsup closed this as completed in 09616ac Feb 2, 2017
@Marsup
Copy link
Collaborator

Marsup commented Feb 2, 2017

Thanks ! Good spot !

@Marsup Marsup added this to the 10.2.1 milestone Feb 2, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants