govalidator
govalidator copied to clipboard
How is `"length(min|max)": ByteLength,` supposed to work?
I tried several options:
valid:"length(min)=1"
valid:"length(min):1"
valid:"length(1|255)"
valid:"length(1,255)"
This never returns any error nor does it catch an empty input. Can someone help me out?
As was described in struct here: https://github.com/asaskevich/govalidator/blob/master/validator_test.go#L1668 And in test: https://github.com/asaskevich/govalidator/blob/master/validator_test.go#L1829
Can you give a short snippet with sample?
Been working on this with a colleague and having:
type UserDataPatch struct {
GivenName string `json:"givenName,omitempty"`
FullName string `json:"fullName,omitempty" valid:"length(1|2)"`
Password string `json:"-" gorm:"-"`
... etc …
}
results in the FullName being considered valid.
We then looked at the tests and added in the following:
To TestLengthStruct
:
{LengthStruct{""}, false},
and to to TestStringLengthStruct
we added:
{StringLengthStruct{""}, false},
Both tests fail. However, adding {"", "1", "2", false},
to TestByteLength
passes.
If need be I can make a PR with the updated tests. Not sure how you want to tackle this. I'm happy to fix it up if you have any particular approach in mind.
what is the status of this issue?
Still open and needs resolution. I haven't had time to look into it yet.
Could you provide a full working example of this issue please?
The length validator is broken.
Use case: change zero to, say, 10 here: https://github.com/asaskevich/govalidator/blob/master/validator_test.go#L2342
Then make food
an empty string here:
https://github.com/asaskevich/govalidator/blob/master/validator_test.go#L2342
This test will incorrectly pass.
maybe this will help you
#162
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.