diff --git a/feedparser/parsers/json.py b/feedparser/parsers/json.py index ef6633e8..f90f29ab 100644 --- a/feedparser/parsers/json.py +++ b/feedparser/parsers/json.py @@ -85,7 +85,7 @@ def parse_entry(self, e): if src in e: entry[dst] = e[src] - content = [] + entry["content"] = content = [] if "content_html" in e: c = FeedParserDict() c["value"] = sanitize_html( @@ -98,8 +98,10 @@ def parse_entry(self, e): c["value"] = e["content_text"] c["type"] = "text" content.append(c) - if content: - entry["content"] = content + if not content: + raise ValueError( + f"item {entry['id']=} has neither 'content_text' nor 'content_html'" + ) if "date_published" in e: entry["published"] = e["date_published"] diff --git a/tests/json/no_content.json b/tests/json/no_content.json new file mode 100644 index 00000000..296a84ac --- /dev/null +++ b/tests/json/no_content.json @@ -0,0 +1,17 @@ +{ + "__TEST__": "Description: basic JSON tests Expect: bozo and 'neither' in str(bozo_exception) -->", + "version": "https://jsonfeed.org/version/1", + "title": "no content", + "home_page_url": "https://example.org/", + "feed_url": "https://example.org/feed.json", + "icon": "https://example.org/feed.png", + "author": { "name": "me" }, + "items": [ + { + "id": "1", + "author": { "name": "you", "url": "http://example.net/~you" }, + "summary": "Hello, world!\n", + "url": "https://example.org/initial-post" + } + ] +}