From 2798a199aa7d4d4caf3ab300386548caff45af3c Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 6 Apr 2022 21:34:40 -0400 Subject: [PATCH] Fix some pixelfed hashtags not being decodable --- Pachyderm/Sources/Pachyderm/Model/Hashtag.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Pachyderm/Sources/Pachyderm/Model/Hashtag.swift b/Pachyderm/Sources/Pachyderm/Model/Hashtag.swift index d5ea7ff4..184f5229 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