mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 18:40:55 +00:00
Merge pull request #3503 from wtospit/develop
fix: when parse post form it didnt parse fields correctly
This commit is contained in:
commit
3406d58797
2
go.mod
2
go.mod
@ -2,9 +2,9 @@ module github.com/astaxie/beego
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Knetic/govaluate v3.0.0+incompatible // indirect
|
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/goyaml2 v0.0.0-20130207012346-5545475820dd
|
||||||
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542
|
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/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737
|
||||||
github.com/casbin/casbin v1.7.0
|
github.com/casbin/casbin v1.7.0
|
||||||
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58
|
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58
|
||||||
|
1
go.sum
1
go.sum
@ -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 h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg=
|
||||||
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
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 h1:jZtX5jh5IOMu0fpOTC3ayh6QGSPJ/KWOv1lgPvbRw1M=
|
||||||
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
|
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=
|
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542 h1:nYXb+3jF6Oq/j8R/y90XrKpreCxIalBWfeyeKymgOPk=
|
||||||
|
@ -297,10 +297,17 @@ func parseFormToStruct(form url.Values, objT reflect.Type, objV reflect.Value) e
|
|||||||
tag = tags[0]
|
tag = tags[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
value := form.Get(tag)
|
formValues := form[tag]
|
||||||
if len(value) == 0 {
|
var value string
|
||||||
|
if len(formValues) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if len(formValues) == 1 {
|
||||||
|
value = formValues[0]
|
||||||
|
if value == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch fieldT.Type.Kind() {
|
switch fieldT.Type.Kind() {
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
|
@ -111,7 +111,7 @@ func TestHtmlunquote(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseForm(t *testing.T) {
|
func TestParseForm(t *testing.T) {
|
||||||
type ExtendInfo struct {
|
type ExtendInfo struct {
|
||||||
Hobby string `form:"hobby"`
|
Hobby []string `form:"hobby"`
|
||||||
Memo string
|
Memo string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ func TestParseForm(t *testing.T) {
|
|||||||
"date": []string{"2014-11-12"},
|
"date": []string{"2014-11-12"},
|
||||||
"organization": []string{"beego"},
|
"organization": []string{"beego"},
|
||||||
"title": []string{"CXO"},
|
"title": []string{"CXO"},
|
||||||
"hobby": []string{"Basketball"},
|
"hobby": []string{"", "Basketball", "Football"},
|
||||||
"memo": []string{"nothing"},
|
"memo": []string{"nothing"},
|
||||||
}
|
}
|
||||||
if err := ParseForm(form, u); err == nil {
|
if err := ParseForm(form, u); err == nil {
|
||||||
@ -186,8 +186,14 @@ func TestParseForm(t *testing.T) {
|
|||||||
if u.Title != "CXO" {
|
if u.Title != "CXO" {
|
||||||
t.Errorf("Title should equal `CXO`, but got `%v`", u.Title)
|
t.Errorf("Title should equal `CXO`, but got `%v`", u.Title)
|
||||||
}
|
}
|
||||||
if u.Hobby != "Basketball" {
|
if u.Hobby[0] != "" {
|
||||||
t.Errorf("Hobby should equal `Basketball`, but got `%v`", u.Hobby)
|
t.Errorf("Hobby should equal ``, but got `%v`", u.Hobby[0])
|
||||||
|
}
|
||||||
|
if u.Hobby[1] != "Basketball" {
|
||||||
|
t.Errorf("Hobby should equal `Basketball`, but got `%v`", u.Hobby[1])
|
||||||
|
}
|
||||||
|
if u.Hobby[2] != "Football" {
|
||||||
|
t.Errorf("Hobby should equal `Football`, but got `%v`", u.Hobby[2])
|
||||||
}
|
}
|
||||||
if len(u.Memo) != 0 {
|
if len(u.Memo) != 0 {
|
||||||
t.Errorf("Memo's length should equal 0 but got %v", len(u.Memo))
|
t.Errorf("Memo's length should equal 0 but got %v", len(u.Memo))
|
||||||
|
Loading…
Reference in New Issue
Block a user