Skip to content

stripUnknown doesn't work for nested objects #2459

@Koala-gentil

Description

@Koala-gentil

Support plan

  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: v14.6.0
  • module version with issue:
  • last module version without issue:
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information:

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

It looks like stripUnknown doesn't works for nested object when the nested object has invalid fields.

const schema = Joi.object({
    foo: Joi.string(),
    nested: Joi.object({
        bar: Joi.string(),
    })
})

const options = {
    abortEarly: false,
    allowUnknown: true,
    presence: 'required',
    stripUnknown: true,
}

const input = {
    foo: null, // invalid value
    unknown: 'unknown',
    nested: {
        bar: null, // invalid value
        unknown: 'unknown',
    }
}

const { value } = schema.validate(input, options)
// { foo: null, nested: { bar: null, unknown: 'unknown' } }

What was the result you got?

nested.unknow is still present

What result did you expect?

It should have been "stripped"

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