1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-06 17:41:00 +00:00

feat(rss): fallback to enclosure URL when entry URL is missing

This commit is contained in:
Frédéric Guillot 2025-07-19 10:38:19 -07:00
parent 33d55cc4e9
commit d9de9d1852
2 changed files with 35 additions and 1 deletions

View file

@ -79,7 +79,13 @@ func (r *RSSAdapter) BuildFeed(baseURL string) *model.Feed {
// Populate the entry URL.
entryURL := findEntryURL(&item)
if entryURL == "" {
entry.URL = feed.SiteURL
// Fallback to the first enclosure URL if it exists.
if len(entry.Enclosures) > 0 && entry.Enclosures[0].URL != "" {
entry.URL = entry.Enclosures[0].URL
} else {
// Fallback to the feed URL if no entry URL is found.
entry.URL = feed.SiteURL
}
} else {
if absoluteEntryURL, err := urllib.AbsoluteURL(feed.SiteURL, entryURL); err == nil {
entry.URL = absoluteEntryURL

View file

@ -632,6 +632,34 @@ func TestParseEntryWithMultipleAtomLinks(t *testing.T) {
}
}
func TestParseEntryWithoutLinkAndWithEnclosureURLs(t *testing.T) {
data := `<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<link>https://example.org/feed</link>
<item>
<guid isPermaLink="false">guid</guid>
<enclosure url=" " length="155844084" type="audio/mpeg" />
<enclosure url="https://audio-file" length="155844084" type="audio/mpeg" />
<enclosure url="https://another-audio-file" length="155844084" type="audio/mpeg" />
</item>
</channel>
</rss>`
feed, err := Parse("https://example.org/", bytes.NewReader([]byte(data)))
if err != nil {
t.Fatal(err)
}
if len(feed.Entries) != 1 {
t.Fatalf("Expected 1 entry, got: %d", len(feed.Entries))
}
if feed.Entries[0].URL != "https://audio-file" {
t.Errorf("Incorrect entry link, got: %q", feed.Entries[0].URL)
}
}
func TestParseFeedURLWithAtomLink(t *testing.T) {
data := `<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">