govalidator icon indicating copy to clipboard operation
govalidator copied to clipboard

Empty string does not validate as stringlength in the new version

Open elvinchan opened this issue 4 years ago • 5 comments

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 !

elvinchan avatar Mar 20 '20 06:03 elvinchan

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

shiminjia avatar Apr 10 '20 16:04 shiminjia

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

sdowding-koho avatar Jul 16 '20 16:07 sdowding-koho

@elvinchan chan Add required to solve the problem.

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

ygj6 avatar Sep 12 '20 08:09 ygj6

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.

sergeyglazyrindev avatar Oct 17 '21 21:10 sergeyglazyrindev

We also have this problem.

itachipein avatar Nov 23 '21 01:11 itachipein