fix(mac): prevent crash decoding GatewayFrame

This commit is contained in:
Peter Steinberger
2025-12-12 16:37:59 +00:00
parent 9eda40234f
commit bf159bd316
2 changed files with 6 additions and 2 deletions

View File

@@ -585,7 +585,9 @@ public enum GatewayFrame: Codable {
private static func decodePayload<T: Decodable>(_ type: T.Type, from raw: [String: AnyCodable]) throws -> T {
let data = try JSONSerialization.data(withJSONObject: raw)
// raw is [String: AnyCodable] which is not directly JSONSerialization-compatible.
// Round-trip through JSONEncoder so AnyCodable can encode itself safely.
let data = try JSONEncoder().encode(raw)
let decoder = JSONDecoder()
return try decoder.decode(T.self, from: data)
}

View File

@@ -198,7 +198,9 @@ function emitGatewayFrame(): string {
const helper = `
private static func decodePayload<T: Decodable>(_ type: T.Type, from raw: [String: AnyCodable]) throws -> T {
let data = try JSONSerialization.data(withJSONObject: raw)
// raw is [String: AnyCodable] which is not directly JSONSerialization-compatible.
// Round-trip through JSONEncoder so AnyCodable can encode itself safely.
let data = try JSONEncoder().encode(raw)
let decoder = JSONDecoder()
return try decoder.decode(T.self, from: data)
}