Skip to content

Joi.boolean() does not handle strings with trailing spaces #3091

@sdonfro

Description

@sdonfro

Runtime

node.js

Runtime version

22.15.1

Module version

17.13.3

Last module version without issue

No response

Used with

No response

Any other relevant information

No response

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

When validating a String as a boolean, I would expect "true " (with a trailing space) to be validated to be true.

This fails, but I would expect it to succeed:

Joi.boolean().validate('true ')

The handling seems inconsistent with numbers for example, which work as I expect.

Joi.number().validate('123 ')
// gives { value: 123 }

What was the result you got?

{
  value: 'true ',
  error: [Error [ValidationError]: "value" must be a boolean] {
    _original: 'true ',
    details: [ [Object] ]
  }
}

What result did you expect?

{ value: true }

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