Skip to content

Chaining string.insensitive() will not convert values with lowercase/uppercase modifiers #1191

@rooftopsparrow

Description

@rooftopsparrow

Context

  • node version: v6.10.2
  • joi version: v10.4.2
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information: macOS 10.12.14

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

I thought it was fairly confusing that these options do not work together

const schema = Joi.string().valid(['A', 'B', 'C']).insensitive().lowercase()
schema.validate('A')
// { error: null, value: 'A' }
// or for uppercase
const anotherSchema = Joi.string().valid(['a', 'b', 'c']).insensitive().uppercase()
anotherSchema.validate('b')
// { error: null, value: 'b' }

Which result you had ?

After validation with schema, the value was 'A'
After validation with anotherSchema, the value was 'b'

What did you expect ?

After validation with schema, the value should be 'a'
After validation with anotherSchema, the value should be 'B'

Now its fine that there is a workaround to just convert the array to the correct casing and use:

Joi.string().valid(['a', 'b', 'c']).lowercase();
schema.validate('A')
// { error: null, value: 'a' }

but seems like odd behavior for this to not work with both. I can submit a PR if you agree.

Thanks for Joi!

Metadata

Metadata

Assignees

Labels

breaking changesChange that can breaking existing codebugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions