From 1b64604dedbb8a00145bf8e8263833d6651c98d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Mon, 28 Oct 2024 18:04:17 +0100 Subject: [PATCH] Os_fcm_notif: data fields cannot contain arbitrary JSON data. --- src/os_fcm_notif.eliom | 20 +++++++++++++------- src/os_fcm_notif.eliomi | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/os_fcm_notif.eliom b/src/os_fcm_notif.eliom index 4ea51eef..4399f89f 100644 --- a/src/os_fcm_notif.eliom +++ b/src/os_fcm_notif.eliom @@ -91,13 +91,15 @@ module Options = struct end module Data = struct - type t = (string * Yojson.Safe.t) list + type t = (string * [`String of string | `Int of int]) list let to_list t = t - let to_json t = `Assoc t + let to_json t = `Assoc (t : t :> (string * Yojson.Safe.t) list) let empty () = [] let add_raw_string key value data = (key, `String value) :: data - let add_raw_json key value data = (key, value) :: data + + let add_raw_json key value data = + (key, `String (Yojson.Safe.to_string value)) :: data module PhoneGap = struct let add_message str t = add_raw_string "message" str t @@ -108,7 +110,7 @@ module Data = struct let add_notification_channel_id id t = ("android_channel_id", `String id) :: t - let add_notification_id id t = ("notId", `Int id) :: t + let add_notification_id id t = ("notId", `String (string_of_int id)) :: t let add_summary_text str t = add_raw_string "summaryText" str t module Style = struct @@ -136,14 +138,18 @@ module Data = struct let add_actions left right t = let actions_list = `List [Action.to_json left; Action.to_json right] in - ("actions", actions_list) :: t + ("actions", `String (Yojson.Safe.to_string actions_list)) :: t let add_led_color a r g b t = let json_int_list = `List [`Int a; `Int r; `Int g; `Int b] in - ("ledColor", json_int_list) :: t + ("ledColor", `String (Yojson.Safe.to_string json_int_list)) :: t let add_vibration_pattern pattern t = - ("vibrationPattern", `List (List.map (fun x -> `Int x) pattern)) :: t + ( "vibrationPattern" + , `String + (Yojson.Safe.to_string (`List (List.map (fun x -> `Int x) pattern))) + ) + :: t let add_badge nb t = ("badge", `Int nb) :: t diff --git a/src/os_fcm_notif.eliomi b/src/os_fcm_notif.eliomi index f8505d80..1ba33aab 100644 --- a/src/os_fcm_notif.eliomi +++ b/src/os_fcm_notif.eliomi @@ -175,7 +175,7 @@ module Data : sig val to_json : t -> Yojson.Safe.t - val to_list : t -> (string * Yojson.Safe.t) list + val to_list : t -> (string * [`String of string | `Int of int]) list (** [to_list data] returns the representation of the data as a list of tuples [(data_key, json_value)]. *)