Skip to content

Commit

Permalink
Fix unmarshaling datetime and base64 for JSONRPC
Browse files Browse the repository at this point in the history
JSONRPC marshals these as string, but then trying to unmarshal would raise an exception.
We need to accept String when unmarshaling DateTime and Base64 too.

Some type safety is lost, because JSON doesn't have a way to distinguish between these (XMLRPC does).

Update the unit test to check that this now works.

Signed-off-by: Edwin Török <[email protected]>
  • Loading branch information
edwintorok committed Nov 20, 2024
1 parent ade14a5 commit 75f1af6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lib/rpc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ let string_of_rpc = function


let dateTime_of_rpc = function
| DateTime s -> s
| DateTime s | String s -> s
| x -> failwith (Printf.sprintf "Expected DateTime, got '%s'" (to_string x))


let base64_of_rpc = function
| Base64 s -> Base64.decode_exn s
| Base64 s | String s -> Base64.decode_exn s
| x -> failwith (Printf.sprintf "Expected base64, got '%s'" (to_string x))


Expand Down
3 changes: 1 addition & 2 deletions tests/lib/test_roundtrip.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ let make_tests name to_wire pp_wire of_wire =
| _ -> failwith "bad value")
; make_test "unit" unit () Rpc.rpc_of_unit Rpc.unit_of_rpc
; make_test "Int32.compat" int32 Int32.min_int (fun i -> Rpc.Int32 i) Rpc.int32_of_rpc
(* JSONRPC is broken here, will be reenabled in followup commits
; make_test "DateTime" string "2024-01-01" Rpc.rpc_of_dateTime Rpc.dateTime_of_rpc
; make_test "Base64" string "\x01\x00\x02" rpc_of_base64_encode Rpc.base64_of_rpc*)
; make_test "Base64" string "\x01\x00\x02" rpc_of_base64_encode Rpc.base64_of_rpc
]


Expand Down

0 comments on commit 75f1af6

Please sign in to comment.