fix ignore walking on form mapping (#1942) (#1943)

This commit is contained in:
Dmitry Kutakov 2019-11-01 03:47:40 +01:00 committed by thinkerou
parent 0f951956d0
commit db9174ae0c
2 changed files with 14 additions and 3 deletions

View File

@ -51,6 +51,10 @@ func mappingByPtr(ptr interface{}, setter setter, tag string) error {
}
func mapping(value reflect.Value, field reflect.StructField, setter setter, tag string) (bool, error) {
if field.Tag.Get(tag) == "-" { // just ignoring this field
return false, nil
}
var vKind = value.Kind()
if vKind == reflect.Ptr {
@ -112,9 +116,6 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter
tagValue = field.Tag.Get(tag)
tagValue, opts := head(tagValue, ",")
if tagValue == "-" { // just ignoring this field
return false, nil
}
if tagValue == "" { // default value is FieldName
tagValue = field.Name
}

View File

@ -269,3 +269,13 @@ func TestMappingMapField(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, map[string]int{"one": 1}, s.M)
}
func TestMappingIgnoredCircularRef(t *testing.T) {
type S struct {
S *S `form:"-"`
}
var s S
err := mappingByPtr(&s, formSource{}, "form")
assert.NoError(t, err)
}