Repository navigation
Resolve relative links and images against the feed's URL - #194
Merged
Merged
Conversation
Since 0.2.0 the feed is downloaded with requests and its bytes are passed to feedparser.parse(), so feedparser no longer knows where the document came from. Relative link, image and <img src> values in summaries stayed relative (e.g. /news/1), which a dashboard then resolves against the Home Assistant host instead of the feed's site. fetch_feed now returns the content together with the final URL after redirects, and the new parse_feed() hands that URL to feedparser as Content-Location, which is what it resolved against in 0.1.12. The config flow validation uses the same helper. Fixes #183 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FvqVzfJq7yZSkZfSyG3YHT
iantrich
marked this pull request as ready for review
November 17, 2026 23:11
# Conflicts: # custom_components/feedparser/reader.py # tests/test_hardening.py
Merged
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.
Fixes #183.
Problem
Since 0.2.0 the feed is downloaded with
requests, and only its bytes are passed tofeedparser.parse(). Without the document's URL, feedparser can't make relative URLs absolute. Solink,imageand thesrcof images insummarycame out as/news/1, which a dashboard resolves against the Home Assistant host instead of the feed's site. 0.1.12 resolved them, because feedparser downloaded the feed itself.Fix
fetch_feednow returns aFetchedFeed(content, url).urlis the final URL after redirects (response.url), which is what feedparser used in 0.1.12.parse_feed()inreader.pypasses that URL to feedparser asContent-Location, the approach suggested in the issue. The sensor and the config-flow validation both use it.link/news/1https://example.com/news/1image/img/1.jpghttps://example.com/img/1.jpgsrcinsummary/img/1.jpghttps://example.com/img/1.jpgFor
file://feeds the base is the file URL, so/news/1becomesfile:///news/1, which matches 0.1.12. A relative link wasn't usable in that case before either.Tests
test_relative_urls_are_made_absolute: a real local HTTP server serves a relative-URL feed behind a 301 redirect. The test checkslink,imageand the image insummary. It also checks that a path-relative link (item/2) resolves against the URL the redirect led to, not the configured one. It fails onmasterand passes here.test_proxy.pyandtest_config_flow.pyare updated for the new return type.tests/data. Saved feeds are read viafile://, and resolving against a file URL doesn't show the bug.🤖 Generated with Claude Code
https://claude.ai/code/session_01FvqVzfJq7yZSkZfSyG3YHT