hapijs / hapijs/joi

Joi.date().min(Joi.ref('field')) breaks original sended object

Open
#2,933 2 comments 0 reactions 0 assignees 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): yes
* *is this issue affecting a production system?* (yes/no): yes

#### Context

* *node version*: 19.6.0
* *module version with issue*: 17.9.1
* *last module version without issue*: i don't tested in other module
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): expressjs
* *any other relevant information*:

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

```js
const Joi = require('joi');

const input = {
query: {
periodStart: "2023-02-11T14:23:03.576Z",
periodEnd: "2023-03-23T14:23:03.576Z",
}
}

const schema = Joi.object({
query: Joi.object({
periodStart: Joi.date(),
periodEnd: Joi.date().min(Joi.ref('query.periodStart')).max('now'),
}),
}).options({
allowUnknown: true,
abortEarly: false
})

await schema.validateAsync(input)
```

#### What was the result you got?

```js
const receivedResult = {
query: {}
}
```

#### What result did you expect?

```js
const expectedResult = {
query: {
periodStart: new Date("2023-02-11T14:23:03.576Z"),
periodEnd: new Date("2023-03-23T14:23:03.576Z"),
}
}
```

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.