JSON conformance test fixes

- Spot an Any without a type URL
- In the conformance test runner, catch exceptions due to generally-invalid JSON
This commit is contained in:
Jon Skeet 2016-01-13 14:05:06 +00:00
parent 73c003c309
commit f2fe50bfc5
3 changed files with 16 additions and 0 deletions

View File

@ -101,6 +101,10 @@ namespace Google.Protobuf.Conformance
{
return new ConformanceResponse { ParseError = e.Message };
}
catch (InvalidJsonException e)
{
return new ConformanceResponse { ParseError = e.Message };
}
switch (request.RequestedOutputFormat)
{
case global::Conformance.WireFormat.JSON:

View File

@ -762,6 +762,13 @@ namespace Google.Protobuf
Assert.Throws<InvalidOperationException>(() => Any.Parser.ParseJson(json));
}
[Test]
public void Any_NoTypeUrl()
{
string json = "{ \"foo\": \"bar\" }";
Assert.Throws<InvalidProtocolBufferException>(() => Any.Parser.ParseJson(json));
}
[Test]
public void Any_WellKnownType()
{

View File

@ -464,6 +464,11 @@ namespace Google.Protobuf
{
tokens.Add(token);
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