Skip to content

Commit

Permalink
jsonutil: ignore empty slice length when decoding (shurcooL#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-rich authored Aug 2, 2023
1 parent 3ca82a0 commit 9585e63
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/jsonutil/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ func (d *decoder) decode() error {
if v.Kind() == reflect.Slice {
// we want to append the template item copy
// so that all the inner structure gets preserved
copied, err := copyTemplate(v.Index(0))
if err != nil {
return fmt.Errorf("failed to copy template: %w", err)
if v.Len() != 0 {
copied, err := copyTemplate(v.Index(0))
if err != nil {
return fmt.Errorf("failed to copy template: %w", err)
}
v.Set(reflect.Append(v, copied)) // v = append(v, T).
f = v.Index(v.Len() - 1)
someSliceExist = true
}
v.Set(reflect.Append(v, copied)) // v = append(v, T).
f = v.Index(v.Len() - 1)
someSliceExist = true
}
d.vs[i] = append(d.vs[i], f)
}
Expand Down

0 comments on commit 9585e63

Please sign in to comment.