mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
"gvalid length" compatible with only one parameter
This commit is contained in:
@ -31,6 +31,8 @@ func (v *Validator) checkLength(value, ruleKey, ruleVal string, customMsgMap map
|
||||
if len(array) > 0 {
|
||||
if v, err := strconv.Atoi(strings.TrimSpace(array[0])); err == nil {
|
||||
min = v
|
||||
// compatible with only one parameter
|
||||
max = v
|
||||
}
|
||||
}
|
||||
if len(array) > 1 {
|
||||
|
||||
@ -658,6 +658,17 @@ func Test_Length(t *testing.T) {
|
||||
if m := gvalid.CheckValue(context.TODO(), "12345", rule, nil); m == nil {
|
||||
t.Error("长度校验失败")
|
||||
}
|
||||
// only one parameter
|
||||
rule2 := "length:5"
|
||||
if m := gvalid.CheckValue(context.TODO(), "1234", rule2, nil); m == nil {
|
||||
t.Error(m)
|
||||
}
|
||||
if m := gvalid.CheckValue(context.TODO(), "12345", rule2, nil); m != nil {
|
||||
t.Error(m)
|
||||
}
|
||||
if m := gvalid.CheckValue(context.TODO(), "123456", rule2, nil); m == nil {
|
||||
t.Error("长度校验失败")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_MinLength(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user