diff options
author | Jon Skeet <jonskeet@google.com> | 2016-01-15 10:55:36 +0000 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2016-01-15 10:55:36 +0000 |
commit | 888e71bdfc4918dbc16b62788c808cf415b7a8b0 (patch) | |
tree | 518e089494f329415402fbe44aee814c32daa8d0 /csharp/src/Google.Protobuf.Test | |
parent | 1a34ac03bed31434caa110acc25537d871966f9d (diff) | |
download | protobuf-888e71bdfc4918dbc16b62788c808cf415b7a8b0.tar.gz protobuf-888e71bdfc4918dbc16b62788c808cf415b7a8b0.tar.bz2 protobuf-888e71bdfc4918dbc16b62788c808cf415b7a8b0.zip |
Prohibit null values in repeated and map fields in JSON
Diffstat (limited to 'csharp/src/Google.Protobuf.Test')
-rw-r--r-- | csharp/src/Google.Protobuf.Test/JsonParserTest.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index b12fe895..790d7e89 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -171,6 +171,36 @@ namespace Google.Protobuf } [Test] + public void RepeatedField_NullElementProhibited() + { + string json = "{ \"repeated_foreign_message\": [null] }"; + Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json)); + } + + [Test] + public void RepeatedField_NullOverallValueAllowed() + { + string json = "{ \"repeated_foreign_message\": null }"; + Assert.AreEqual(new TestAllTypes(), TestAllTypes.Parser.ParseJson(json)); + } + + [Test] + [TestCase("{ \"mapInt32Int32\": { \"10\": null }")] + [TestCase("{ \"mapStringString\": { \"abc\": null }")] + [TestCase("{ \"mapInt32ForeignMessage\": { \"10\": null }")] + public void MapField_NullValueProhibited(string json) + { + Assert.Throws<InvalidProtocolBufferException>(() => TestMap.Parser.ParseJson(json)); + } + + [Test] + public void MapField_NullOverallValueAllowed() + { + string json = "{ \"mapInt32Int32\": null }"; + Assert.AreEqual(new TestMap(), TestMap.Parser.ParseJson(json)); + } + + [Test] public void IndividualWrapperTypes() { Assert.AreEqual(new StringValue { Value = "foo" }, StringValue.Parser.ParseJson("\"foo\"")); |