From a21c1e22bcba0fe24a84b18c51138e32879ce250 Mon Sep 17 00:00:00 2001 From: blankie Date: Wed, 29 Nov 2023 15:40:58 +1100 Subject: [PATCH] Fix handling posts/fields with missing keys https://social.kernel.org/@monsieuricon/Ac6oYwtLhess6uil1c https://social.kernel.org/@monsieuricon/Ac8RXJRqxTfUrM1xQG --- models.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/models.cpp b/models.cpp index 31201f7..bb90951 100644 --- a/models.cpp +++ b/models.cpp @@ -19,7 +19,9 @@ void from_json(const json& j, Emoji& emoji) { void from_json(const json& j, AccountField& field) { j.at("name").get_to(field.name); field.value_html = j.at("value").get(); - if (j.at("verified_at").is_null()) { + // https://social.kernel.org/@monsieuricon/Ac6oYwtLhess6uil1c + // https://social.kernel.org/@monsieuricon/Ac8RXJRqxTfUrM1xQG + if (!j.contains("verified_at") || j["verified_at"].is_null()) { field.verified_at = -1; } else { field.verified_at = parse_rfc3339(j["verified_at"].get_ref()); @@ -104,7 +106,8 @@ void from_json(const json& j, Post& post) { j.at("replies_count").get_to(post.replies_count); j.at("reblogs_count").get_to(post.reblogs_count); j.at("favourites_count").get_to(post.favorites_count); - if (!j.at("edited_at").is_null()) { + // https://social.kernel.org/@monsieuricon/Ac6oYwtLhess6uil1c + if (j.contains("edited_at") && !j["edited_at"].is_null()) { post.edited_at = parse_rfc3339(j["edited_at"].get_ref()); } else { post.edited_at = -1; @@ -117,7 +120,8 @@ void from_json(const json& j, Post& post) { j.at("account").get_to(post.account); j.at("media_attachments").get_to(post.media_attachments); j.at("emojis").get_to(post.emojis); - if (!j.at("poll").is_null()) { + // https://social.kernel.org/@monsieuricon/Ac6oYwtLhess6uil1c + if (j.contains("poll") && !j["poll"].is_null()) { post.poll = j["poll"].get(); } }