hapijs / hapijs/joi

TypeError: Method get %TypedArray%.prototype.buffer called on incompatible receiver [object Object]

Open
#2,884 2 comments 0 reactions 1 assignee Claimed by @Marsup View on GitHub
support
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

#### Support plan

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

#### Context

* *node version*: v18.12.1
* *module version with issue*: v17.7.0
* *last module version without issue*: n/a
* *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?
Define a Joi object with a property `buffer` and validate it with a buffer as the object:

```js
Joi.object().keys({
a: Joi.object().keys({
buffer: Joi.string().required(),
}),
}).validate({
a: Buffer.from('hi', 'utf8'),
});
```

#### What was the result you got?
```sh
[..]/node_modules/joi/lib/types/keys.js:103
const item = value[key];
^
TypeError: Method get %TypedArray%.prototype.buffer called on incompatible receiver [object Object]
at get buffer [as buffer] ()
at Object.validate ([..]/node_modules/joi/lib/types/keys.js:103:35)
at Object.exports.validate ([..]/node_modules/joi/lib/validator.js:328:26)
at internals.Base.$_validate ([..]/node_modules/joi/lib/base.js:774:26)
at Object.validate ([..]/node_modules/joi/lib/types/keys.js:108:45)
at Object.exports.validate ([..]/node_modules/joi/lib/validator.js:328:26)
at Object.internals.entry ([..]/node_modules/joi/lib/validator.js:145:28)
at Object.exports.entry ([..]/node_modules/joi/lib/validator.js:27:30)
at internals.Base.validate ([..]/node_modules/joi/lib/base.js:548:26)
at Object. ([..]/test.ts:7:4)
```

#### What result did you expect?
No error being thrown

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.