Repository navigation
Don't parse an HTTP error page's body as feed content - #597
Open
hikmetba-bit wants to merge 1 commit into
Open
hikmetba-bit wants to merge 1 commit into
hikmetba-bit wants to merge 1 commit into
Conversation
feedparser.parse('http://httpstat.us/500') fed the 500 error page's
body straight to the XML parser, producing a confusing
bozo_exception (e.g. SAXParseException('syntax error')) that looks
like a malformed feed. The HTTP failure is already recorded cleanly
in result['status'], set unconditionally a few lines above.
http.get() now returns an empty body for any response with
status_code >= 400, matching the existing empty-body return already
used for a RequestException. bozo/bozo_exception are then left
unset by the empty-content parse, same as parsing b"".
Co-Authored-By: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #460.
http.get()returned the HTTP response body regardless of status code, so a server's 500 error page (HTML, plain text, whatever the error handler produces) got fed straight into the XML parser. That produces abozo_exceptionthat looks like a malformed feed, when the real problem — the HTTP failure — is already recorded cleanly inresult["status"]a few lines above.Fix: in
feedparser/http.py,get()now returnsb""for any response withstatus_code >= 400, the same empty-body return it already uses when the request itself raisesRequestException.status/headers/hrefare still set from the real response before that check, so callers can still see exactly what happened (status == 500), they just don't also get a misleading parse errorbozo_exception.Test plan
tests/test_http.pywith two tests using theresponsesmock already used elsewhere in the suite (tests/helpers.py):test_error_status_body_is_not_parsed: a mocked 500 response with a plain-text body →status == 500,bozois falsy, nobozo_exceptionkey,entries == [].test_success_status_body_is_still_parsed: a mocked 200 RSS response, to confirm normal parsing is unaffected.pytest tests/→ 4299 passed, 8 skipped (was 4297 passed, 8 skipped onmainbefore this change — the +2 are the new tests, zero regressions).mypy feedparser/http.py→ no issues.flake8on both changed files → clean.Co-Authored-By: Claude Sonnet 5 [email protected]
🤖 Generated with Claude Code