From 87471ed9c84da7c60916e3d7481326e8efc15855 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sat, 21 Jan 2023 11:32:47 +0100 Subject: [PATCH] Safer HTML String decode --- Packages/Models/Sources/Models/Alias/HTMLString.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Packages/Models/Sources/Models/Alias/HTMLString.swift b/Packages/Models/Sources/Models/Alias/HTMLString.swift index eea061ad..f229c15f 100644 --- a/Packages/Models/Sources/Models/Alias/HTMLString.swift +++ b/Packages/Models/Sources/Models/Alias/HTMLString.swift @@ -10,9 +10,13 @@ public struct HTMLString: Decodable, Equatable { public let statusesURLs: [URL] public let asSafeMarkdownAttributedString: AttributedString - public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - htmlValue = try container.decode(String.self) + public init(from decoder: Decoder) { + do { + let container = try decoder.singleValueContainer() + htmlValue = try container.decode(String.self) + } catch { + htmlValue = "" + } do { asMarkdown = try HTMLParser().parse(html: htmlValue)