Skip to content

Commit f42192d

Browse files
author
Pedro López Cabanillas
committed
Fix for ticket Astn#109 - validate request.id property to conform the json-rpc 2.0 standard
1 parent a192a9d commit f42192d

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

AustinHarris.JsonRpcTestN/Test.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,15 @@ public void TestWrongParamType()
18991899
Assert.IsTrue(result.Result.Contains("\"code\":-32603"));
19001900
}
19011901

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

19031912
private static void AssertJsonAreEqual(string expectedJson, string actualJson)
19041913
{

Json-Rpc/JsonRpcProcessor.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j
9393
jsonResponse.Error = handler.ProcessParseException(jsonRpc,
9494
new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'"));
9595
}
96+
else if (!isSimpleValueType(jsonRequest.Id))
97+
{
98+
jsonResponse.Error = handler.ProcessParseException(jsonRpc,
99+
new JsonRpcException(-32600, "Invalid Request", "Id property must be either null or string or integer."));
100+
}
96101
else
97102
{
98103
jsonResponse.Id = jsonRequest.Id;
@@ -174,5 +179,15 @@ private static bool isSingleRpc(string json)
174179
}
175180
return true;
176181
}
182+
183+
private static bool isSimpleValueType(object property)
184+
{
185+
if (property == null)
186+
return true;
187+
return property.GetType() == typeof(System.String) ||
188+
property.GetType() == typeof(System.Int64) ||
189+
property.GetType() == typeof(System.Int32) ||
190+
property.GetType() == typeof(System.Int16);
191+
}
177192
}
178193
}

0 commit comments

Comments
 (0)