asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
6.04k stars 555 forks source link

Empty string does not validate as stringlength in the new version #374

Open elvinchan opened 4 years ago

elvinchan commented 4 years ago

Hi everyone: A struct defined like this:

type Input struct {
    Keyword string `valid:"stringlength(3|64)"`
}

What I expect is:

Keyword == "" --> valid
Keyword == "e" --> invalid
Keyword == "eee" --> valid

It is worked in the version v0.0.0-20190424111038-f61b66f89f4a But after updated to version v0.0.0-20200108200545-475eaeb16496, the empty string does not validate

Keyword == "" --> invalid

I found it was the break change due to switch from isEmptyValue to isFieldSet

So I want to know, is the design of stringlength has changed ? Or just a bug ? If the design has changed, how do I implement the requirement "empty or specified length scope of string" ?

Thanks a lot for any help !

shiminjia commented 4 years ago

I met the same problem with you. Did you solve this problem? 你解决这个问题了吗?求解。

sdowding-koho commented 4 years ago

We are also having this issue? any update on this?

ygj6 commented 4 years ago

@elvinchan chan Add required to solve the problem.

type Input struct {
    Keyword string `valid:"stringlength(3|64) , required"`
}
sergeyglazyrindev commented 3 years ago

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.

itachipein commented 2 years ago

We also have this problem.