Skip to content

Resolve relative links and images against the feed's URL - #194

Merged
iantrich merged 2 commits into
masterfrom
claude/relative-urls
Nov 18, 2026
Merged

iantrich merged 2 commits into
masterfrom
claude/relative-urls

Conversation

@iantrich

@iantrich iantrich commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Fixes #183.

Problem

Since 0.2.0 the feed is downloaded with requests, and only its bytes are passed to feedparser.parse(). Without the document's URL, feedparser can't make relative URLs absolute. So link, image and the src of images in summary came 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_feed now returns a FetchedFeed(content, url). url is the final URL after redirects (response.url), which is what feedparser used in 0.1.12.
  • A new parse_feed() in reader.py passes that URL to feedparser as Content-Location, the approach suggested in the issue. The sensor and the config-flow validation both use it.
field before after
link /news/1 https://example.com/news/1
image /img/1.jpg https://example.com/img/1.jpg
image src in summary /img/1.jpg https://example.com/img/1.jpg

For file:// feeds the base is the file URL, so /news/1 becomes file:///news/1, which matches 0.1.12. A relative link wasn't usable in that case before either.

Tests

  • New test_relative_urls_are_made_absolute: a real local HTTP server serves a relative-URL feed behind a 301 redirect. The test checks link, image and the image in summary. It also checks that a path-relative link (item/2) resolves against the URL the redirect led to, not the configured one. It fails on master and passes here.
  • test_proxy.py and test_config_flow.py are updated for the new return type.
  • I tested this with a local HTTP server rather than a saved feed in tests/data. Saved feeds are read via file://, and resolving against a file URL doesn't show the bug.
  • The full offline suite passes (240 tests). pre-commit (black, ruff, mypy) is clean, and the integration compiles under Python 3.13.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FvqVzfJq7yZSkZfSyG3YHT

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
iantrich marked this pull request as ready for review November 17, 2026 23:11
# Conflicts:
#	custom_components/feedparser/reader.py
#	tests/test_hardening.py
@iantrich
iantrich merged commit 8907882 into master Nov 18, 2026
9 checks passed
@iantrich
iantrich deleted the claude/relative-urls branch November 18, 2026 01:10
@iantrich iantrich mentioned this pull request Nov 18, 2026
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.

Relative links and image URLs are no longer made absolute

2 participants