From 885031bed9e54876fb262921b11df23aa00cedb6 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 12 Apr 2023 10:41:15 +0200 Subject: Don't generate invalid JSON if an attachment has no description. --- mastoapi.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index be1ba61..3cfaa34 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -506,7 +506,12 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url")); matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url")); matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url")); - matte = xs_dict_append(matte, "description", xs_dict_get(aobj, "name")); + + const char *name = xs_dict_get(aobj, "name"); + if (xs_is_null(name)) + name = ""; + + matte = xs_dict_append(matte, "description", name); matt = xs_list_append(matt, matte); } @@ -730,6 +735,14 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, *ctype = "application/json"; status = 200; + { + xs *j = xs_json_loads(*body); + if (j == NULL) { + srv_debug(0, xs_fmt("mastoapi timeline: bad JSON")); + srv_archive_error("mastoapi_timeline", "bad JSON", req, *body); + } + } + srv_debug(0, xs_fmt("mastoapi timeline: returned %d entries", xs_list_len(out))); } else { -- cgit v1.2.3