Skip to content

Cannot read property 'delete' of undefined #2165

@i3fox

Description

@i3fox

With the update to version 16.1.5 I have an exception.

With version 16.1.4 it works correctly.

Context

  • node version: 10.16.3
  • joi version: 16.1.5
  • environment: node

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

const Joi = require('@hapi/joi');

const itemsSchema = Joi.object().pattern(Joi.string(), Joi.object({
  res: Joi.string(),
  params: Joi.object({
    custom: Joi.string().when('...res', {
      is: 'custom',
      then: Joi.required(),
      otherwise: Joi.any().strip(),
    }),
  }),
}));

const data = {
  item1: {
    res: 'automatic',
    params: {
      custom: 'x',
    },
  },
  item2: {
    res: 'manual',
    params: {
      custom: 'y',
    },
  },
};

itemsSchema.validate(data);

Which result you had ?

TypeError: Cannot read property 'delete' of undefined
at internals.Shadow.override (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/state.js:147:20)
at module.exports.internals.State.restore (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/state.js:63:34)
at internals.Base.$_match (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/base.js:662:15)
at internals.Base._generate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/base.js:835:24)
at Object.exports.validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/validator.js:163:25)
at internals.Base.$_validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/base.js:751:26)
at Object.validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/types/keys.js:107:45)
at Object.exports.validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/validator.js:314:26)
at internals.Base.$_validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/base.js:751:26)
at Object.validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/types/keys.js:107:45)

What did you expect ?

{
  item1: {
    res: 'automatic',
    params: {
    },
  },
  item2: {
    res: 'manual',
    params: {
    },
  },
};

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