diff --git a/encoding/prototext/decode.go b/encoding/prototext/decode.go index 8951e6bf..4e4d0c93 100644 --- a/encoding/prototext/decode.go +++ b/encoding/prototext/decode.go @@ -420,10 +420,14 @@ func unmarshalMapKey(input text.Value, fd pref.FieldDescriptor) (pref.MapKey, er // unmarshalMapMessageValue unmarshals given message-type text.Value into a protoreflect.Map for // the given MapKey. -func (o UnmarshalOptions) unmarshalMapMessageValue(input text.Value, pkey pref.MapKey, _ pref.FieldDescriptor, mmap pref.Map) error { +func (o UnmarshalOptions) unmarshalMapMessageValue(input text.Value, pkey pref.MapKey, fd pref.FieldDescriptor, mmap pref.Map) error { var value [][2]text.Value - if input.Type() != 0 { + switch input.Type() { + case 0: + case text.Message: value = input.Message() + default: + return errors.New("%v contains invalid value: %v", fd.FullName(), input) } val := mmap.NewValue() if err := o.unmarshalMessage(value, val.Message()); err != nil { diff --git a/encoding/prototext/decode_test.go b/encoding/prototext/decode_test.go index 03ba5527..525304a9 100644 --- a/encoding/prototext/decode_test.go +++ b/encoding/prototext/decode_test.go @@ -948,6 +948,16 @@ int32_to_str: { key: 100 value: 101 } +`, + wantErr: true, + }, { + desc: "map contains invalid message value", + inputMessage: &pb3.Maps{}, + inputText: ` +str_to_nested: { + key: "one" + value: 1 +} `, wantErr: true, }, {