Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions AustinHarris.JsonRpcTestN/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,15 @@ public void TestWrongParamType()
Assert.IsTrue(result.Result.Contains("\"code\":-32603"));
}

[Test()]
public void TestWrongIdType()
{
string request = @"{method:'TestOptionalParamdouble',params:{input:5},id:{what:4,that:3}}";
var result = JsonRpcProcessor.Process(request);
result.Wait();
Assert.IsTrue(result.Result.Contains("error"));
Assert.IsTrue(result.Result.Contains("\"code\":-32600"));
}

private static void AssertJsonAreEqual(string expectedJson, string actualJson)
{
Expand Down
15 changes: 15 additions & 0 deletions Json-Rpc/JsonRpcProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j
jsonResponse.Error = handler.ProcessParseException(jsonRpc,
new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'"));
}
else if (!isSimpleValueType(jsonRequest.Id))
{
jsonResponse.Error = handler.ProcessParseException(jsonRpc,
new JsonRpcException(-32600, "Invalid Request", "Id property must be either null or string or integer."));
}
else
{
jsonResponse.Id = jsonRequest.Id;
Expand Down Expand Up @@ -174,5 +179,15 @@ private static bool isSingleRpc(string json)
}
return true;
}

private static bool isSimpleValueType(object property)
{
if (property == null)
return true;
return property.GetType() == typeof(System.String) ||
property.GetType() == typeof(System.Int64) ||
property.GetType() == typeof(System.Int32) ||
property.GetType() == typeof(System.Int16);
}
}
}