encoding/jsonpb,textpb: fix handling of duplicate oneof fields
Unmarshaling should fail if multiple fields in the same oneof exists in
the input.
Change-Id: I76efd88681a50c18f3eaf770c9eb48727efb412b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/170517
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/encoding/textpb/decode_test.go b/encoding/textpb/decode_test.go
index 2f4045c..2f14029 100644
--- a/encoding/textpb/decode_test.go
+++ b/encoding/textpb/decode_test.go
@@ -523,20 +523,13 @@
},
},
}, {
- desc: "oneof set to last value",
+ desc: "oneof set to more than one field",
inputMessage: &pb3.Oneofs{},
inputText: `
-oneof_nested: {
- s_string: "nested message"
-}
-oneof_enum: TEN
-oneof_string: "wins"
+oneof_enum: ZERO
+oneof_string: "hello"
`,
- wantMessage: &pb3.Oneofs{
- Union: &pb3.Oneofs_OneofString{
- OneofString: "wins",
- },
- },
+ wantErr: true,
}, {
desc: "repeated scalar using same field name",
inputMessage: &pb2.Repeats{},