Accept a FreshRSS "Export" .zip directly for OPML import

FreshRSS's Export feature produces a .zip (an .opml.xml plus a starred-
articles .json this app doesn't import) rather than a bare .opml file —
uploading that zip as-is failed with "That file doesn't look like a valid
OPML export" since defusedxml can't parse a zip as XML.

apps.feeds.opml.extract_opml_bytes detects a zip upload and pulls the
.opml/.opml.xml member out of it before parsing; a bare .opml upload is
returned unchanged, so existing behavior is untouched. Verified against
the reporter's actual FreshRSS export (18 feeds across 6 categories) both
directly through extract_opml_bytes/parse_opml and as a real upload
through the running app.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ksmithandClaude Sonnet 5 committed 2026-10-30 21:45:16 -06:00
1 parent 753ae9efc7
commit f818b11041
6 files changed
+86 -4

No files matched your search

+28 -1
View File
@@ -1,3 +1,4 @@
import zipfile
from io import BytesIO
import pytest
@@ -6,7 +7,7 @@ from django.contrib.auth import get_user_model
from apps.articles.models import SubscriptionTag, Tag
from .models import Feed, Subscription
from .opml import export_opml, import_opml, parse_opml
from .opml import export_opml, extract_opml_bytes, import_opml, parse_opml
User = get_user_model()
@@ -54,6 +55,32 @@ def alice(db):
return User.objects.create_user("alice", password="pw-alice-123")
def _zip_of(filename: str, content: bytes) -> bytes:
buf = BytesIO()
with zipfile.ZipFile(buf, "w") as archive:
archive.writestr(filename, content)
return buf.getvalue()
class TestExtractOPMLBytes:
def test_bare_opml_is_returned_unchanged(self):
assert extract_opml_bytes(SIMPLE_OPML) == SIMPLE_OPML
def test_extracts_opml_from_a_freshrss_style_export_zip(self):
# FreshRSS's own "Export" produces exactly this: an .opml.xml plus
# a starred-articles .json we don't need for feed import.
zipped = _zip_of("feeds_2026-10-30.opml.xml", SIMPLE_OPML)
with zipfile.ZipFile(BytesIO(zipped), "a") as archive:
archive.writestr("starred_2026-10-30.json", b'{"items": []}')
assert extract_opml_bytes(zipped) == SIMPLE_OPML
def test_zip_with_no_opml_member_raises(self):
zipped = _zip_of("starred_2026-10-30.json", b'{"items": []}')
with pytest.raises(ValueError):
extract_opml_bytes(zipped)
class TestParseOPML:
def test_parses_tagged_and_untagged_entries(self):
entries = parse_opml(BytesIO(SIMPLE_OPML))