From 87fb14fcbae09a3e88c2d8ea2b5ee711471d4b86 Mon Sep 17 00:00:00 2001 From: Brian R Date: Tue, 1 Aug 2023 15:24:14 -0400 Subject: [PATCH 1/2] fix fatal error passing in non supported types to JSONSerialization.data(withJsonObject:...) --- Sources/Realtime/RealtimeClient.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Realtime/RealtimeClient.swift b/Sources/Realtime/RealtimeClient.swift index b50a6f4..489595a 100644 --- a/Sources/Realtime/RealtimeClient.swift +++ b/Sources/Realtime/RealtimeClient.swift @@ -645,7 +645,7 @@ public class RealtimeClient: TransportDelegate { joinRef: String? = nil ) { let callback: (() throws -> Void) = { - let body: [Any?] = [joinRef, ref, topic, event, payload] + let body: [Any?] = [joinRef, ref, topic.rawValue, event.rawValue, payload] let data = self.encode(body) self.logItems("push", "Sending \(String(data: data, encoding: String.Encoding.utf8) ?? "")") From 1f4bef63a654ae1576e01ad7bd8d445d423147f7 Mon Sep 17 00:00:00 2001 From: Brian R Date: Tue, 1 Aug 2023 17:26:10 -0400 Subject: [PATCH 2/2] add assertion for valid JSON object to encode function --- Sources/Realtime/Defaults.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Realtime/Defaults.swift b/Sources/Realtime/Defaults.swift index 296c352..b006b13 100644 --- a/Sources/Realtime/Defaults.swift +++ b/Sources/Realtime/Defaults.swift @@ -45,7 +45,8 @@ public enum Defaults { /// Default encode function, utilizing JSONSerialization.data public static let encode: (Any) -> Data = { json in - try! JSONSerialization + assert(JSONSerialization.isValidJSONObject(json), "Invalid JSON object") + return try! JSONSerialization .data( withJSONObject: json, options: JSONSerialization.WritingOptions()