Skip to content

Commit

Permalink
jsonpb: error on scalar enum provided for repeated enums instead of p…
Browse files Browse the repository at this point in the history
…anic
  • Loading branch information
eleniums authored and dsnet committed Jun 6, 2018
1 parent 3a3da3a commit 64db29d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions jsonpb/jsonpb.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,9 @@ func (u *Unmarshaler) unmarshalValue(target reflect.Value, inputValue json.RawMe
target.Set(reflect.New(targetType.Elem()))
target = target.Elem()
}
if targetType.Kind() != reflect.Int32 {
return fmt.Errorf("invalid target %q for enum %s", targetType.Kind(), prop.Enum)
}
target.SetInt(int64(n))
return nil
}
Expand Down
1 change: 1 addition & 0 deletions jsonpb/jsonpb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ var unmarshalingShouldError = []struct {
{"Timestamp containing invalid character", `{"ts": "2014-05-13T16:53:20\U005a"}`, &pb.KnownTypes{}},
{"StringValue containing invalid character", `{"str": "\U00004E16\U0000754C"}`, &pb.KnownTypes{}},
{"StructValue containing invalid character", `{"str": "\U00004E16\U0000754C"}`, &stpb.Struct{}},
{"repeated proto3 enum with non array input", `{"rFunny":"PUNS"}`, &proto3pb.Message{RFunny: []proto3pb.Message_Humour{}}},
}

func TestUnmarshalingBadInput(t *testing.T) {
Expand Down

0 comments on commit 64db29d

Please sign in to comment.