fix: when parse post form it didnt parse fields which have same name but the first index is empty but another is not

This commit is contained in:
Witaya Tospitakkul 2019-01-25 00:15:40 +07:00
parent d0c744ae6a
commit 12fdc04f1b
3 changed files with 23 additions and 9 deletions

2
go.mod
View File

@ -2,9 +2,9 @@ module github.com/astaxie/beego
require (
github.com/Knetic/govaluate v3.0.0+incompatible // indirect
github.com/OwnLocal/goes v1.0.0
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542
github.com/OwnLocal/goes v1.0.0
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737
github.com/casbin/casbin v1.7.0
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58

1
go.sum
View File

@ -1,5 +1,6 @@
github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg=
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM=
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd h1:jZtX5jh5IOMu0fpOTC3ayh6QGSPJ/KWOv1lgPvbRw1M=
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542 h1:nYXb+3jF6Oq/j8R/y90XrKpreCxIalBWfeyeKymgOPk=

View File

@ -297,8 +297,21 @@ func parseFormToStruct(form url.Values, objT reflect.Type, objV reflect.Value) e
tag = tags[0]
}
if fieldT.Type.Kind() == reflect.Slice {
found := false
for _, v := range form[tag] {
if len(v) != 0 {
found = true
break
}
}
if !found {
continue
}
}
value := form.Get(tag)
if len(value) == 0 {
if (fieldT.Type.Kind() != reflect.Slice) && len(value) == 0 {
continue
}