mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 12:30:54 +00:00
Empty field in validator.Error when label struct tag is not declared #4222
This commit is contained in:
parent
5973ef107c
commit
5618df8c76
@ -269,6 +269,11 @@ func (v *Validation) apply(chk Validator, obj interface{}) *Result {
|
|||||||
Field := ""
|
Field := ""
|
||||||
Label := ""
|
Label := ""
|
||||||
parts := strings.Split(key, ".")
|
parts := strings.Split(key, ".")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
Field = parts[0]
|
||||||
|
Name = parts[1]
|
||||||
|
Label = Field
|
||||||
|
}
|
||||||
if len(parts) == 3 {
|
if len(parts) == 3 {
|
||||||
Field = parts[0]
|
Field = parts[0]
|
||||||
Name = parts[1]
|
Name = parts[1]
|
||||||
|
@ -607,3 +607,28 @@ func TestCanSkipAlso(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFieldNoEmpty(t *testing.T) {
|
||||||
|
type User struct {
|
||||||
|
Name string `json:"name" valid:"Match(/^[a-zA-Z][a-zA-Z0-9._-]{0,31}$/)"`
|
||||||
|
}
|
||||||
|
u := User{
|
||||||
|
Name: "*",
|
||||||
|
}
|
||||||
|
|
||||||
|
valid := Validation{}
|
||||||
|
b, err := valid.Valid(u)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if b {
|
||||||
|
t.Fatal("validation should be passed")
|
||||||
|
}
|
||||||
|
if len(valid.Errors) == 0 {
|
||||||
|
t.Fatal("validation should be passed")
|
||||||
|
}
|
||||||
|
validErr := valid.Errors[0]
|
||||||
|
if len(validErr.Field) == 0 {
|
||||||
|
t.Fatal("validation should be passed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user