Skip to content

Fix JSON Feed parser: use correct key for date_updated and prefer content_html - #558

Open
danishashko wants to merge 1 commit into
kurtmckee:mainfrom
danishashko:fix-json-feed-date-updated-key
Open

danishashko wants to merge 1 commit into
kurtmckee:mainfrom
danishashko:fix-json-feed-date-updated-key

Conversation

@danishashko

Copy link
Copy Markdown

Two bugs in the JSON Feed parser:

1. KeyError when parsing date_updated

parse_entry() checks "date_updated" in e (correct per the JSON Feed spec) but then reads e["date_modified"] which doesn't exist in JSON Feed. Every entry with a date_updated field raises a KeyError.

# current (broken):
if "date_updated" in e:
    entry["updated"] = e["date_modified"]        # KeyError
    entry["updated_parsed"] = _parse_date(e["date_modified"])  # KeyError

# fixed:
if "date_updated" in e:
    entry["updated"] = e["date_updated"]
    entry["updated_parsed"] = _parse_date(e["date_updated"])

2. content_text silently wins over content_html

The current if/elif returns content_text whenever present, even if content_html is also present. The JSON Feed 1.1 spec recommends HTML-capable clients prefer content_html. Swapping the branches gives richer content by default and matches the spec intent.

Both bugs are in feedparser/parsers/json.py, no new imports needed.

@rupayon123 rupayon123 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both JSON Feed 1 and 1.1 use date_modified for the item modification time. The guard appears to be the typo here; changing the reads to date_updated still ignores valid feeds. I reproduced this with date_modified-only items on current main: parsing succeeds, but updated and updated_parsed are absent. Could you change the guard to date_modified and keep the existing reads, with a regression for that input?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants