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

Error messages do not distinguish between numbers and strings!Easily misleading #2706

Closed
galaxy-s10 opened this issue Nov 21, 2021 · 2 comments
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@galaxy-s10
Copy link

  const schema = Joi.object({
    isComment: [1, 2],
    status: ['1', '2'],
  });
  try {
    const res = await schema.validateAsync(
      { isComment: '1', status: 1 },
      {
        abortEarly: false,
        allowUnknown: false,
        presence: 'required',
      }
    );
    console.log('joi验证通过', res);
  } catch (error) {
    console.log('joi验证不通过', error); // "isComment" must be one of [1, 2]. "status" must be one of [1, 2]
  }
@hueniverse hueniverse self-assigned this Dec 2, 2021
@hueniverse hueniverse added the feature New functionality or improvement label Dec 2, 2021
@hueniverse hueniverse added this to the 17.5.0 milestone Dec 2, 2021
@galaxy-s10
Copy link
Author

galaxy-s10 commented Jan 24, 2022

@hueniverse , hi guy, I tried. It seems that it hasn't been repaired yet. What I expect is the following results:

  const schema = Joi.object({
    isComment: [1, 2],
    status: ['1', '2'],
  });
  try {
    const res = await schema.validateAsync(
      { isComment: '1', status: 1 },
      {
        abortEarly: false,
        allowUnknown: false,
        presence: 'required',
      }
    );
    console.log('joi验证通过', res);
  } catch (error) {
    // now
    console.log('joi验证不通过', error); // "isComment" must be one of [1, 2]. "status" must be one of [1, 2]
    // expect
    console.log('joi验证不通过', error); // "isComment" must be one of [1, 2]. "status" must be one of ['1', '2']

  }

@hueniverse
Copy link
Contributor

@galaxy-s10 Have you read the commit info and noticed the new required config to make it wrap values in quotes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

2 participants