Safer HTML String decode

This commit is contained in:
Thomas Ricouard 2023-01-21 11:32:47 +01:00
parent 523cb48cd1
commit 87471ed9c8

View file

@ -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)