Skip to content

Accept an absolute file path as feed_url again - #195

Merged
iantrich merged 2 commits into
masterfrom
claude/bare-file-path
Nov 18, 2026
Merged

iantrich merged 2 commits into
masterfrom
claude/bare-file-path

Conversation

@iantrich

Copy link
Copy Markdown
Member

Fixes #187, using option 1 from the issue: treat a value starting with / as a file:// URL.

Problem

0.1.12 accepted feed_url: /config/www/feed.xml, because feedparser opened local files itself. Since 0.2.0 the download goes through requests, which raises MissingSchema for a plain path. The YAML import doesn't fetch the feed, so it still created the entry, and the entry then stayed in setup retry indefinitely. Home Assistant logs those retries only at INFO level.

Fix

normalize_feed_url() in source.py strips the value and turns an absolute path into a percent-encoded file:// URL. Spaces and # in the path are encoded. It's applied wherever a feed URL enters:

  • Setup and reconfigure forms (_source_from_input): the entry stores the file:// URL.
  • YAML import: the import runs on every start, so YAML entries already stuck in retry are fixed on the next restart. The lookup of entries imported by 1.0.0 still compares the raw value, since that's what 1.0.0 stored.
  • URL entities: an input_text or similar entity holding a path works too.

Relative paths such as www/feed.xml are left as they are and stay invalid. I didn't guess a base directory for them.

Also included: fetch_feed now uses with session.get(...) as response:. Without it, a file:// fetch left its file open until garbage collection, which emitted a ResourceWarning. That leak exists on master too, but this PR sends more feeds through file://, and the new tests surfaced the warning.

Docs

The README configuration reference and the URL-entity note now mention absolute paths. I didn't change strings.json or the translations. The UI text already says local file URLs are supported, and rewording it would need new German and Greek translations for little gain.

Not in this PR

The issue's other point is still open: MissingSchema and InvalidURL from a URL that's still bad, like ftp: or a relative path in YAML, should be reported as a configuration error (for example a Repairs issue), not retried as an outage. That changes how the coordinator classifies errors, so I'd suggest a follow-up.

Tests

  • test_normalize_feed_url: absolute path, encoding of spaces and #, URLs unchanged, relative path left alone.
  • test_plain_path_with_special_characters_is_read: the encoded URL still opens the file through requests-file.
  • test_yaml_feed_url_can_be_a_plain_path, test_user_flow_accepts_plain_path and test_url_entity_can_hold_a_plain_path cover the three entry points end to end. All three fail on master.

The full offline suite passes (248 tests). pre-commit (black, ruff, mypy) is clean, and the integration compiles under Python 3.13.


Generated by Claude Code

Before 0.2.0, feedparser opened a plain path such as /config/www/feed.xml
itself. Since the download moved to requests, such a value fails with
MissingSchema. The YAML import doesn't fetch the feed, so the entry was
created anyway and then stayed in setup retry indefinitely.

normalize_feed_url() turns an absolute path into a percent-encoded file://
URL. It is applied wherever a feed URL enters: the setup and reconfigure
form, the YAML import (so existing YAML entries are fixed on the next
start) and the state of a URL entity. Relative paths are left alone and
stay invalid.

fetch_feed now also closes its response, which closes the file that a
file:// URL opened instead of leaving it to the garbage collector.

Fixes #187

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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/fetch.py
#	tests/test_hardening.py
@iantrich
iantrich merged commit efe35ae into master Nov 18, 2026
9 checks passed
@iantrich
iantrich deleted the claude/bare-file-path branch November 18, 2026 01:14
@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.

A local file path as feed_url (without file://) no longer works and the entry retries forever

2 participants