Skip to content

Commit

Permalink
Fix: nil map
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jul 15, 2023
1 parent 163faa1 commit 7d7f084
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/bcd/ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,11 @@ func TestTypedAst_FromJSONSchema(t *testing.T) {
tree: `{"prim":"list","args":[{"prim":"list","args":[{"prim":"nat"}]}],"annots":["%update_cycles"]}`,
data: `{"update_cycles":[{"@list_2":[{"@nat_3":"12"}]}]}`,
want: `[[{"int":"12"}]]`,
}, {
name: "nil map",
tree: `{"prim":"map","args":[{"prim":"string"},{"prim":"string"}]}`,
data: `{"@map_1": null}`,
want: `[]`,
},
}
for _, tt := range tests {
Expand Down
3 changes: 3 additions & 0 deletions internal/bcd/ast/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ func (m *Map) FromJSONSchema(data map[string]interface{}) error {
for key := range data {
if key == m.GetName() {
val := data[key]
if val == nil {
return nil
}
arrVal, ok := val.([]interface{})
if !ok {
return errors.Wrapf(consts.ErrInvalidType, "Map.FromJSONSchema %T", val)
Expand Down

0 comments on commit 7d7f084

Please sign in to comment.