Repository navigation
Accept an absolute file path as feed_url again - #195
Merged
Merged
Conversation
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 <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/fetch.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 #187, using option 1 from the issue: treat a value starting with
/as afile://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 throughrequests, which raisesMissingSchemafor 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()insource.pystrips the value and turns an absolute path into a percent-encodedfile://URL. Spaces and#in the path are encoded. It's applied wherever a feed URL enters:_source_from_input): the entry stores thefile://URL.input_textor similar entity holding a path works too.Relative paths such as
www/feed.xmlare left as they are and stay invalid. I didn't guess a base directory for them.Also included:
fetch_feednow useswith session.get(...) as response:. Without it, afile://fetch left its file open until garbage collection, which emitted aResourceWarning. That leak exists onmastertoo, but this PR sends more feeds throughfile://, 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.jsonor 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:
MissingSchemaandInvalidURLfrom a URL that's still bad, likeftp: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 throughrequests-file.test_yaml_feed_url_can_be_a_plain_path,test_user_flow_accepts_plain_pathandtest_url_entity_can_hold_a_plain_pathcover the three entry points end to end. All three fail onmaster.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