Skip to content

Commit d50d30b

Browse files
committed
Merge compat_jsonrpc_weirdversions
2 parents 574d3ab + 4bb5473 commit d50d30b

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

src/rpc/request.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,8 @@ void JSONRPCRequest::parse(const UniValue& valRequest)
218218
m_json_version = JSONRPCVersion::V1_LEGACY;
219219
const UniValue& jsonrpc_version = request.find_value("jsonrpc");
220220
if (!jsonrpc_version.isNull()) {
221-
if (!jsonrpc_version.isStr()) {
222-
throw JSONRPCError(RPC_INVALID_REQUEST, "jsonrpc field must be a string");
223-
}
224-
// The "jsonrpc" key was added in the 2.0 spec, but some older documentation
225-
// incorrectly included {"jsonrpc":"1.0"} in a request object, so we
226-
// maintain that for backwards compatibility.
227-
if (jsonrpc_version.get_str() == "1.0") {
228-
m_json_version = JSONRPCVersion::V1_LEGACY;
229-
} else if (jsonrpc_version.get_str() == "2.0") {
221+
if (jsonrpc_version.isStr() && jsonrpc_version.get_str() == "2.0") {
230222
m_json_version = JSONRPCVersion::V2;
231-
} else {
232-
throw JSONRPCError(RPC_INVALID_REQUEST, "JSON-RPC version not supported");
233223
}
234224
}
235225

test/functional/interface_rpc.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,13 @@ def test_batch_requests(self):
172172
self.log.info("Testing nonstandard jsonrpc 1.0 version number is accepted...")
173173
self.test_batch_request(lambda idx: BatchOptions(request_fields={"jsonrpc": "1.0"}))
174174

175-
self.log.info("Testing unrecognized jsonrpc version number is rejected...")
175+
self.log.info("Testing nonstandard jsonrpc 1.0 version number is accepted as a Number...")
176+
self.test_batch_request(lambda idx: BatchOptions(request_fields={"jsonrpc": 1.0}))
177+
178+
self.log.info("Testing unrecognized jsonrpc version number is accepted as if 1.0...")
176179
self.test_batch_request(lambda idx: BatchOptions(
177180
request_fields={"jsonrpc": "2.1"},
178-
response_fields={"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "JSON-RPC version not supported"}}))
181+
))
179182

180183
def test_http_status_codes(self):
181184
self.log.info("Testing HTTP status codes for JSON-RPC 1.1 requests...")
@@ -201,11 +204,11 @@ def test_http_status_codes(self):
201204
expect_http_rpc_status(200, RPC_INVALID_PARAMETER, self.nodes[0], "getblockhash", [42], 2, False)
202205
# force-send invalidly formatted requests
203206
response, status = send_json_rpc(self.nodes[0], {"jsonrpc": 2, "method": "getblockcount"})
204-
assert_equal(response, {"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "jsonrpc field must be a string"}})
205-
assert_equal(status, 400)
207+
assert_equal(response, {"result": 0, "error": None})
208+
assert_equal(status, 200)
206209
response, status = send_json_rpc(self.nodes[0], {"jsonrpc": "3.0", "method": "getblockcount"})
207-
assert_equal(response, {"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "JSON-RPC version not supported"}})
208-
assert_equal(status, 400)
210+
assert_equal(response, {"result": 0, "error": None})
211+
assert_equal(status, 200)
209212

210213
self.log.info("Testing HTTP status codes for JSON-RPC 2.0 notifications...")
211214
# Not notification: id exists

test/functional/test_framework/authproxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def _get_response(self):
192192
response = json.loads(responsedata, parse_float=decimal.Decimal)
193193
elapsed = time.time() - req_start_time
194194
if "error" in response and response["error"] is None:
195-
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, json.dumps(response["result"], default=serialization_fallback, ensure_ascii=self.ensure_ascii)))
195+
log.debug("<-%s- [%.6f] %s" % (response.get("id"), elapsed, json.dumps(response["result"], default=serialization_fallback, ensure_ascii=self.ensure_ascii)))
196196
else:
197197
log.debug("<-- [%.6f] %s" % (elapsed, responsedata))
198198
return response, http_response.status

0 commit comments

Comments
 (0)