Commit f2fe50bf authored by Jon Skeet's avatar Jon Skeet

JSON conformance test fixes

- Spot an Any without a type URL
- In the conformance test runner, catch exceptions due to generally-invalid JSON
parent 73c003c3
...@@ -101,6 +101,10 @@ namespace Google.Protobuf.Conformance ...@@ -101,6 +101,10 @@ namespace Google.Protobuf.Conformance
{ {
return new ConformanceResponse { ParseError = e.Message }; return new ConformanceResponse { ParseError = e.Message };
} }
catch (InvalidJsonException e)
{
return new ConformanceResponse { ParseError = e.Message };
}
switch (request.RequestedOutputFormat) switch (request.RequestedOutputFormat)
{ {
case global::Conformance.WireFormat.JSON: case global::Conformance.WireFormat.JSON:
......
...@@ -762,6 +762,13 @@ namespace Google.Protobuf ...@@ -762,6 +762,13 @@ namespace Google.Protobuf
Assert.Throws<InvalidOperationException>(() => Any.Parser.ParseJson(json)); Assert.Throws<InvalidOperationException>(() => Any.Parser.ParseJson(json));
} }
[Test]
public void Any_NoTypeUrl()
{
string json = "{ \"foo\": \"bar\" }";
Assert.Throws<InvalidProtocolBufferException>(() => Any.Parser.ParseJson(json));
}
[Test] [Test]
public void Any_WellKnownType() public void Any_WellKnownType()
{ {
......
...@@ -464,6 +464,11 @@ namespace Google.Protobuf ...@@ -464,6 +464,11 @@ namespace Google.Protobuf
{ {
tokens.Add(token); tokens.Add(token);
token = tokenizer.Next(); token = tokenizer.Next();
if (tokenizer.ObjectDepth < typeUrlObjectDepth)
{
throw new InvalidProtocolBufferException("Any message with no @type");
}
} }
// Don't add the @type property or its value to the recorded token list // Don't add the @type property or its value to the recorded token list
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment