Closed nicktalb closed 10 months ago
Thanks for reporting this :+1: that indeed is a problem and not the intended behavior.
Damn, trim
and minLength
/ maxLength
are also broken in combination.
Trimming should be done first and min/max length checking should be done on the trimmed string, not on the untrimmed string:
const s = st.string({trim: true, minLength: 1, maxLength: 3})
s(' ') === '' // true, should raise an error instead because '' is not long enough
s('abc ') // raises an error but should not because 'abc' is still within maxLength
Gotta fix that too :sweat_smile:
See the following test cases:
(1) Without trim option - optional fields are correctly not returned as they are not defined in the input.
(2) With trim option - all optional fields incorrectly returned with
undefined
values.Many libraries will treat the two objects differently which can cause downstream issues.