diff --git a/mapstructure.go b/mapstructure.go index bae0c39a..84beaabd 100644 --- a/mapstructure.go +++ b/mapstructure.go @@ -847,21 +847,21 @@ func (d *Decoder) decodeMapFromStruct(name string, dataVal reflect.Value, val re // Determine the name of the key in the map if index := strings.Index(tagValue, ","); index != -1 { if tagValue[:index] == "-" { - continue; + continue } // If "omitempty" is specified in the tag, it ignores empty values. - if strings.Index(tagValue[index + 1:], "omitempty") != -1 && isEmptyValue(v) { + if strings.Index(tagValue[index+1:], "omitempty") != -1 && isEmptyValue(v) { continue } // If "squash" is specified in the tag, we squash the field down. - squash = !squash && strings.Index(tagValue[index + 1:], "squash") != -1 + squash = !squash && strings.Index(tagValue[index+1:], "squash") != -1 if squash && v.Kind() != reflect.Struct { return fmt.Errorf("cannot squash non-struct type '%s'", v.Type()) } keyName = tagValue[:index] } else if len(tagValue) > 0 { - if tagValue == "-" { + if tagValue == "-" { continue } keyName = tagValue diff --git a/mapstructure_test.go b/mapstructure_test.go index 7274f14f..1701394a 100644 --- a/mapstructure_test.go +++ b/mapstructure_test.go @@ -354,6 +354,27 @@ func TestBasic_Struct(t *testing.T) { } } +func TestBasic_interfaceStruct(t *testing.T) { + t.Parallel() + + input := map[string]interface{}{ + "vstring": "foo", + } + + var iface interface{} = &Basic{} + err := Decode(input, &iface) + if err != nil { + t.Fatalf("got an err: %s", err) + } + + expected := &Basic{ + Vstring: "foo", + } + if !reflect.DeepEqual(iface, expected) { + t.Fatalf("bad: %#v", iface) + } +} + func TestDecode_BasicSquash(t *testing.T) { t.Parallel()