From d631d4d382c03dca258af015aa071dbf9c5844b8 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 6 May 2021 13:52:50 -0500 Subject: [PATCH] Initialize the author as nil if it is unparsable. Fixes #3034 --- .../Sources/Account/Feedbin/FeedbinEntry.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Account/Sources/Account/Feedbin/FeedbinEntry.swift b/Account/Sources/Account/Feedbin/FeedbinEntry.swift index 82b40e186..741d6abfc 100644 --- a/Account/Sources/Account/Feedbin/FeedbinEntry.swift +++ b/Account/Sources/Account/Feedbin/FeedbinEntry.swift @@ -10,7 +10,7 @@ import Foundation import RSParser import RSCore -final class FeedbinEntry: Codable { +final class FeedbinEntry: Decodable { let articleID: Int let feedID: Int @@ -50,14 +50,25 @@ final class FeedbinEntry: Codable { } } -struct FeedbinEntryJSONFeed: Codable { +struct FeedbinEntryJSONFeed: Decodable { let jsonFeedAuthor: FeedbinEntryJSONFeedAuthor? + enum CodingKeys: String, CodingKey { case jsonFeedAuthor = "author" } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + do { + jsonFeedAuthor = try container.decode(FeedbinEntryJSONFeedAuthor.self, forKey: .jsonFeedAuthor) + } catch { + jsonFeedAuthor = nil + } + } + } -struct FeedbinEntryJSONFeedAuthor: Codable { +struct FeedbinEntryJSONFeedAuthor: Decodable { let url: String? let avatarURL: String? enum CodingKeys: String, CodingKey {