diff --git a/Pachyderm/Sources/Pachyderm/Model/Hashtag.swift b/Pachyderm/Sources/Pachyderm/Model/Hashtag.swift index d5ea7ff497..184f522956 100644 --- a/Pachyderm/Sources/Pachyderm/Model/Hashtag.swift +++ b/Pachyderm/Sources/Pachyderm/Model/Hashtag.swift @@ -7,6 +7,8 @@ // import Foundation +import WebURL +import WebURLFoundationExtras public class Hashtag: Codable { public let name: String @@ -20,6 +22,18 @@ public class Hashtag: Codable { self.history = nil } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.name = try container.decode(String.self, forKey: .name) + // pixelfed (possibly others) don't fully escape special characters in the hashtag url + if let url = URL(try container.decode(WebURL.self, forKey: .url)) { + self.url = url + } else { + throw DecodingError.dataCorruptedError(forKey: .url, in: container, debugDescription: "unable to convert WebURL to URL") + } + self.history = try container.decodeIfPresent([History].self, forKey: .history) + } + private enum CodingKeys: String, CodingKey { case name case url