forked from shadowfacts/Tusker
Fix some pixelfed hashtags not being decodable
This commit is contained in:
parent
3d0402c1e0
commit
2798a199aa
|
@ -7,6 +7,8 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import WebURL
|
||||||
|
import WebURLFoundationExtras
|
||||||
|
|
||||||
public class Hashtag: Codable {
|
public class Hashtag: Codable {
|
||||||
public let name: String
|
public let name: String
|
||||||
|
@ -20,6 +22,18 @@ public class Hashtag: Codable {
|
||||||
self.history = nil
|
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 {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case name
|
case name
|
||||||
case url
|
case url
|
||||||
|
|
Loading…
Reference in New Issue