Skip to content

Commit a4e8991

Browse files
author
Martin Daetz
committed
fix omitted parms issue
1 parent b718183 commit a4e8991

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

AustinHarris.JsonRpcTest/UnitTest1.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,5 +1345,17 @@ public void TestBatchResult()
13451345

13461346
Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')");
13471347
}
1348+
1349+
[TestMethod]
1350+
public void TestLeftOutParams()
1351+
{
1352+
var request =
1353+
@"{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""id"":1}";
1354+
1355+
var result = JsonRpcProcessor.Process(request);
1356+
result.Wait();
1357+
1358+
Assert.IsFalse(result.Result.Contains(@"error"":{""code"":-32602"), @"According to JSON-RPC 2.0 the ""params"" member MAY be omitted.");
1359+
}
13481360
}
13491361
}

Json-Rpc/Handler.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,6 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null)
200200
{
201201
return new JsonResponse() { Result = null, Error = new JsonRpcException(-32601, "Method not found", "The method does not exist / is not available."), Id = Rpc.Id };
202202
}
203-
if (Rpc.Params is ICollection == false)
204-
{
205-
return new JsonResponse()
206-
{
207-
Result = null,
208-
Error = new JsonRpcException(-32602,
209-
"Invalid params", "The number of parameters could not be counted"),
210-
Id = Rpc.Id
211-
};
212-
}
213203

214204
bool isJObject = Rpc.Params is Newtonsoft.Json.Linq.JObject;
215205
bool isJArray = Rpc.Params is Newtonsoft.Json.Linq.JArray;
@@ -218,7 +208,13 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null)
218208
var metaDataParamCount = metadata.parameters.Count(x => x != null);
219209

220210
var getCount = Rpc.Params as ICollection;
221-
var loopCt = getCount.Count;
211+
var loopCt = 0;
212+
213+
if (getCount != null)
214+
{
215+
loopCt = getCount.Count;
216+
}
217+
222218
var paramCount = loopCt;
223219
if (paramCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount-1].ObjectType.Name.Contains(typeof(JsonRpcException).Name))
224220
{

0 commit comments

Comments
 (0)