Open bambulin opened 3 years ago
I'm getting this as well.
We are trying to validate 0 values for int's and it is also not calling the custom validator.
Please we need this fixed urgently!
I have created a PR to fix this in a non-breaking way https://github.com/asaskevich/govalidator/pull/409
Hello guys! I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back Link to my repo: create issue there and we'll discuss it.
BC Break Report
Empty values are not passed to custom validator.
Summary
Empty values are not passed to custom validator. Unable to distinguish nils as not acceptable and empty vals as acceptable.
Previous behavior
In previous versions an empty values were passed to custom validators so it was possible to distinguish between nils and empty strings or false etc. "require" tag accepted empty values as valid.
Current behavior
Currently empty values or nils are not passed to the custom validator, so there's no possibility to distinguish nil as unacceptable value and empty value as acceptable. Especially if the field is a pointer to another struct that contains bools only and we need to distinguish the nil and the struct with falses as acceptable value. The scenario when we consider nil pointer as all falses is not acceptable since this struct is received via JSON and we need to distinguish if the client provided the falses intentionaly or the request is missing the field completely and unintentionally.
There's validator method
govalidator.SetNilPtrAllowedByRequired()
which enables the exact opposite behavior as desired.So how to distinguish nils as notacceptable values and empty values as acceptable in new version?
How to reproduce