Add enabled flag to string.trim()#1532
Conversation
test/types/string.js
Outdated
|
|
||
| it('disable existing trim flag when passing enabled: false', () => { | ||
|
|
||
| const schema = Joi.string().trim().trim(false); |
There was a problem hiding this comment.
Looks like .trim() is repeated twice here.
I also don't see any tests for .trim(true) or when the parameter to trim is not a boolean to validate that we are checking the type like other calls (ie. .trim(42)).
Last piece on this part would be documentation, this new functionality should be listed in the docs also.
There was a problem hiding this comment.
Hmm, I just follow the implementation of the .truncate(enabled?)
But if it really needed, I'll write some assertion here.
lib/types/string/index.js
Outdated
| trim(enabled) { | ||
|
|
||
| const obj = this._test('trim', undefined, function (value, state, options) { | ||
| enabled = enabled === undefined ? true : !!enabled; |
There was a problem hiding this comment.
Instead of coercing the value here where someone making the call .trim('yes please') would enable trim I would expect us to check the data type like we do in other validation methods. For example: Hoek.assert(typeof base64Options.paddingRequired === 'undefined' || typeof base64Options.paddingRequired === 'boolean', Hoek.assert(typeof base64Options.paddingRequired === 'undefined' || typeof base64Options.paddingRequired === 'boolean', 'paddingRequired must be boolean');
|
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. |
Resolves #1525