@@ -553,12 +553,12 @@ var unmarshalingTests = []struct {
553
553
{"camelName input" , Unmarshaler {}, `{"oBool":true}` , & pb.Simple {OBool : proto .Bool (true )}},
554
554
555
555
{"Duration" , Unmarshaler {}, `{"dur":"3.000s"}` , & pb.KnownTypes {Dur : & durpb.Duration {Seconds : 3 }}},
556
- {"null Duration" , Unmarshaler {}, `{"dur":null}` , & pb.KnownTypes {Dur : & durpb. Duration { Seconds : 0 } }},
556
+ {"null Duration" , Unmarshaler {}, `{"dur":null}` , & pb.KnownTypes {Dur : nil }},
557
557
{"Timestamp" , Unmarshaler {}, `{"ts":"2014-05-13T16:53:20.021Z"}` , & pb.KnownTypes {Ts : & tspb.Timestamp {Seconds : 14e8 , Nanos : 21e6 }}},
558
558
{"PreEpochTimestamp" , Unmarshaler {}, `{"ts":"1969-12-31T23:59:58.999999995Z"}` , & pb.KnownTypes {Ts : & tspb.Timestamp {Seconds : - 2 , Nanos : 999999995 }}},
559
559
{"ZeroTimeTimestamp" , Unmarshaler {}, `{"ts":"0001-01-01T00:00:00Z"}` , & pb.KnownTypes {Ts : & tspb.Timestamp {Seconds : - 62135596800 , Nanos : 0 }}},
560
- {"null Timestamp" , Unmarshaler {}, `{"ts":null}` , & pb.KnownTypes {Ts : & tspb. Timestamp { Seconds : 0 , Nanos : 0 } }},
561
- {"null Struct" , Unmarshaler {}, `{"st": null}` , & pb.KnownTypes {St : & stpb. Struct {} }},
560
+ {"null Timestamp" , Unmarshaler {}, `{"ts":null}` , & pb.KnownTypes {Ts : nil }},
561
+ {"null Struct" , Unmarshaler {}, `{"st": null}` , & pb.KnownTypes {St : nil }},
562
562
{"empty Struct" , Unmarshaler {}, `{"st": {}}` , & pb.KnownTypes {St : & stpb.Struct {}}},
563
563
{"basic Struct" , Unmarshaler {}, `{"st": {"a": "x", "b": null, "c": 3, "d": true}}` , & pb.KnownTypes {St : & stpb.Struct {Fields : map [string ]* stpb.Value {
564
564
"a" : {Kind : & stpb.Value_StringValue {"x" }},
@@ -575,7 +575,7 @@ var unmarshalingTests = []struct {
575
575
}}}},
576
576
}}}},
577
577
}}}},
578
- {"null ListValue" , Unmarshaler {}, `{"lv": null}` , & pb.KnownTypes {Lv : & stpb. ListValue {} }},
578
+ {"null ListValue" , Unmarshaler {}, `{"lv": null}` , & pb.KnownTypes {Lv : nil }},
579
579
{"empty ListValue" , Unmarshaler {}, `{"lv": []}` , & pb.KnownTypes {Lv : & stpb.ListValue {}}},
580
580
{"basic ListValue" , Unmarshaler {}, `{"lv": ["x", null, 3, true]}` , & pb.KnownTypes {Lv : & stpb.ListValue {Values : []* stpb.Value {
581
581
{Kind : & stpb.Value_StringValue {"x" }},
@@ -612,8 +612,17 @@ var unmarshalingTests = []struct {
612
612
{"BoolValue" , Unmarshaler {}, `{"bool":true}` , & pb.KnownTypes {Bool : & wpb.BoolValue {Value : true }}},
613
613
{"StringValue" , Unmarshaler {}, `{"str":"plush"}` , & pb.KnownTypes {Str : & wpb.StringValue {Value : "plush" }}},
614
614
{"BytesValue" , Unmarshaler {}, `{"bytes":"d293"}` , & pb.KnownTypes {Bytes : & wpb.BytesValue {Value : []byte ("wow" )}}},
615
- // `null` is also a permissible value. Let's just test one.
616
- {"null DoubleValue" , Unmarshaler {}, `{"dbl":null}` , & pb.KnownTypes {Dbl : & wpb.DoubleValue {}}},
615
+
616
+ // Ensure that `null` as a value ends up with a nil pointer instead of a [type]Value struct.
617
+ {"null DoubleValue" , Unmarshaler {}, `{"dbl":null}` , & pb.KnownTypes {Dbl : nil }},
618
+ {"null FloatValue" , Unmarshaler {}, `{"flt":null}` , & pb.KnownTypes {Flt : nil }},
619
+ {"null Int64Value" , Unmarshaler {}, `{"i64":null}` , & pb.KnownTypes {I64 : nil }},
620
+ {"null UInt64Value" , Unmarshaler {}, `{"u64":null}` , & pb.KnownTypes {U64 : nil }},
621
+ {"null Int32Value" , Unmarshaler {}, `{"i32":null}` , & pb.KnownTypes {I32 : nil }},
622
+ {"null UInt32Value" , Unmarshaler {}, `{"u32":null}` , & pb.KnownTypes {U32 : nil }},
623
+ {"null BoolValue" , Unmarshaler {}, `{"bool":null}` , & pb.KnownTypes {Bool : nil }},
624
+ {"null StringValue" , Unmarshaler {}, `{"str":null}` , & pb.KnownTypes {Str : nil }},
625
+ {"null BytesValue" , Unmarshaler {}, `{"bytes":null}` , & pb.KnownTypes {Bytes : nil }},
617
626
}
618
627
619
628
func TestUnmarshaling (t * testing.T ) {
@@ -756,4 +765,4 @@ func (m *dynamicMessage) MarshalJSONPB(jm *Marshaler) ([]byte, error) {
756
765
func (m * dynamicMessage ) UnmarshalJSONPB (jum * Unmarshaler , js []byte ) error {
757
766
m .rawJson = string (js )
758
767
return nil
759
- }
768
+ }
0 commit comments