Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Fix not reading to end of argument JSON on binding error (#2319) (#2360
Browse files Browse the repository at this point in the history
)
  • Loading branch information
analogrelay committed May 30, 2018
1 parent 3fa10f9 commit 0452f46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -209,6 +209,7 @@ private HubMessage ParseMessage(Utf8BufferTextReader textReader, IInvocationBind
case ArgumentsPropertyName:
JsonUtils.CheckRead(reader);

int initialDepth = reader.Depth;
if (reader.TokenType != JsonToken.StartArray)
{
throw new InvalidDataException($"Expected '{ArgumentsPropertyName}' to be of type {JTokenType.Array}.");
Expand All @@ -231,6 +232,14 @@ private HubMessage ParseMessage(Utf8BufferTextReader textReader, IInvocationBind
catch (Exception ex)
{
argumentBindingException = ExceptionDispatchInfo.Capture(ex);

// Could be at any point in argument array JSON when an error is thrown
// Read until the end of the argument JSON array
while (reader.Depth == initialDepth && reader.TokenType == JsonToken.StartArray ||
reader.Depth > initialDepth)
{
JsonUtils.CheckRead(reader);
}
}
}
break;
Expand Down
Expand Up @@ -291,6 +291,18 @@ public void DateTimeReturnValuePreservesUtcKind(string input)
Assert.Equal(DateTimeKind.Utc, dt.Kind);
}

[Fact]
public void ReadToEndOfArgumentArrayOnError()
{
var binder = new TestBinder(new[] { typeof(string) });
var protocol = new JsonHubProtocol();
var data = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(Frame("{'type':1,'invocationId':'42','target':'foo','arguments':[[],{'target':'foo2'}]}")));
protocol.TryParseMessage(ref data, binder, out var message);
var bindingFailure = Assert.IsType<InvocationBindingFailureMessage>(message);

Assert.Equal("foo", bindingFailure.Target);
}

private static string Frame(string input)
{
var data = Encoding.UTF8.GetBytes(input);
Expand Down

0 comments on commit 0452f46

Please sign in to comment.