mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
feat(rss): add workaround for RSS item title with HTML content
This commit is contained in:
parent
502db64b28
commit
a3ce03cc9d
3 changed files with 32 additions and 3 deletions
|
@ -173,13 +173,13 @@ func findFeedAuthor(rssChannel *RSSChannel) string {
|
|||
}
|
||||
|
||||
func findEntryTitle(rssItem *RSSItem) string {
|
||||
title := rssItem.Title
|
||||
title := sanitizer.StripTags(rssItem.Title.Inner)
|
||||
|
||||
if rssItem.DublinCoreTitle != "" {
|
||||
title = rssItem.DublinCoreTitle
|
||||
}
|
||||
|
||||
return html.UnescapeString(strings.TrimSpace(title))
|
||||
return html.UnescapeString(html.UnescapeString(strings.TrimSpace(title)))
|
||||
}
|
||||
|
||||
func findEntryURL(rssItem *RSSItem) string {
|
||||
|
|
|
@ -1023,6 +1023,30 @@ func TestParseEntryTitleWithWhitespaces(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestParseEntryTitleWithInnerHTML(t *testing.T) {
|
||||
data := `<?xml version="1.0" encoding="utf-8"?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>Example</title>
|
||||
<link>http://example.org</link>
|
||||
<item>
|
||||
<title>Test: <b>bold</b></title>
|
||||
<link>http://www.example.org/entries/1</link>
|
||||
<pubDate>Fri, 15 Jul 2005 00:00:00 -0500</pubDate>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>`
|
||||
|
||||
feed, err := Parse("https://example.org/", bytes.NewReader([]byte(data)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if feed.Entries[0].Title != "Test: bold" {
|
||||
t.Errorf("Incorrect entry title, got: %s", feed.Entries[0].Title)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseEntryWithEnclosures(t *testing.T) {
|
||||
data := `<?xml version="1.0" encoding="utf-8"?>
|
||||
<rss version="2.0">
|
||||
|
|
|
@ -111,7 +111,7 @@ type RSSImage struct {
|
|||
|
||||
type RSSItem struct {
|
||||
// Title is the title of the item.
|
||||
Title string `xml:"rss title"`
|
||||
Title RSSTitle `xml:"rss title"`
|
||||
|
||||
// Link is the URL of the item.
|
||||
Link string `xml:"rss link"`
|
||||
|
@ -169,6 +169,11 @@ type RSSItem struct {
|
|||
googleplay.GooglePlayItemElement
|
||||
}
|
||||
|
||||
type RSSTitle struct {
|
||||
Data string `xml:",chardata"`
|
||||
Inner string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
type RSSAuthor struct {
|
||||
XMLName xml.Name
|
||||
Data string `xml:",chardata"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue