diff --git a/binding/form_mapping.go b/binding/form_mapping.go index ec78bfee..d6199c4f 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -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 } diff --git a/binding/form_mapping_test.go b/binding/form_mapping_test.go index c9d6111b..2a560371 100644 --- a/binding/form_mapping_test.go +++ b/binding/form_mapping_test.go @@ -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) +}