Manage empty string with min
- 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?* no
* *is this issue affecting a production system?* not yet
#### Context
* *node version*: 12.16.1
* *module version*:
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): hapi application
* *any other relevant information*:
#### How can we help?
Hello,
I'd like to make joi handle the **string.min** and the **string.empty** with the same behaviour.
This an example code:
```js
const schema: Joi.ObjectSchema = Joi.object({
property: Joi.string().min(2).required(),
});
//first case
let testObject = { property: "" }; // this will trigger string.empty
//second case
let testObject = { property: "1"} // this will trigger string.min
```
What I want to archive is to throw a message like _"The string must be at least X characters long"_ where _X_ is the number inside min.
I'm able to do this for the **string.min** because the exception has a field inside the `context` object (inside the first record in the details array) called `limit` which holds exactly that value, but this doesn't happen for the **string.empty** which only says "string cannot be empty" but no information about the minimum value.
I tried to put `allow("")` so that it might trigger the error for the `min(2)`, but if I put `allow("")` it simply pass with no errors.
Example with `allow`
```js
const schema: Joi.ObjectSchema = Joi.object({
property: Joi.string().allow("").min(2).required(),
});
```
Thanks in advance for any help
Contributor guide
Assessment
This issue has not been assessed yet.