Skip to content

Commit

Permalink
fix ignore walking on form mapping (#1942) (#1943)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkd authored and thinkerou committed Nov 1, 2019
1 parent 0f95195 commit db9174a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions binding/form_mapping.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions binding/form_mapping_test.go
Expand Up @@ -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)
}

0 comments on commit db9174a

Please sign in to comment.