joi icon indicating copy to clipboard operation
joi copied to clipboard

Sanitizing blanks

Open leore opened this issue 12 years ago • 3 comments

Is there a way in joi to change '' or ' ' to null for all optional parameters that are strings?

Right now I have to pass a .allow('') when a parameter is because joi by default does not accept '' and then i have to check each parameter to see if its blank and rename to null.

Can a setting be added to sanitize all empty string and string with spaces to null and an option to allow empty strings?

leore avatar Apr 24 '14 22:04 leore

.allow('') is going to be the setting to allow an empty string. If you want to allow a string which just contains spaces and other whitespace characters, you could use Joi.string().trim().allow(''), but that appears to be failing with the error value must be a string

As far as renaming the param to null, this sounds very specific to your application.

jaw187 avatar Jun 05 '14 15:06 jaw187

I have to disagree here. Typically, forms do not allow users to submit null instead of a blank. And many developers, including myself, like to normalize blanks as null values before persisting them. Every project I've worked on, not just a "specific application".

pekeler avatar Feb 25 '15 22:02 pekeler

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

lock[bot] avatar Jan 09 '20 03:01 lock[bot]