diff --git a/helper/schema/field_reader_map.go b/helper/schema/field_reader_map.go index b2ed73605c..a4345cbcd1 100644 --- a/helper/schema/field_reader_map.go +++ b/helper/schema/field_reader_map.go @@ -56,10 +56,11 @@ func (r *MapFieldReader) readMap(k string) (FieldReadResult, error) { prefix := k + "." r.Map.Range(func(k, v string) bool { if strings.HasPrefix(k, prefix) { + resultSet = true + key := k[len(prefix):] if key != "#" { result[key] = v - resultSet = true } } diff --git a/helper/schema/field_reader_map_test.go b/helper/schema/field_reader_map_test.go index ae4e69b5ea..e2d5342ee3 100644 --- a/helper/schema/field_reader_map_test.go +++ b/helper/schema/field_reader_map_test.go @@ -49,11 +49,14 @@ func TestMapFieldReader(t *testing.T) { func TestMapFieldReader_extra(t *testing.T) { r := &MapFieldReader{ Schema: map[string]*Schema{ - "mapDel": &Schema{Type: TypeMap}, + "mapDel": &Schema{Type: TypeMap}, + "mapEmpty": &Schema{Type: TypeMap}, }, Map: BasicMapReader(map[string]string{ "mapDel": "", + + "mapEmpty.#": "0", }), } @@ -71,6 +74,14 @@ func TestMapFieldReader_extra(t *testing.T) { false, false, }, + + "mapEmpty": { + []string{"mapEmpty"}, + map[string]interface{}{}, + true, + false, + false, + }, } for name, tc := range cases {