helper/schema: FieldReaderMap should mark map as exists if anything set
This commit is contained in:
parent
fa934d96d0
commit
9c10a89cf8
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue