From 04f9c456d5c0942acb1c707199a8f56a55f1d00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sun, 14 Feb 2021 11:09:06 -0800 Subject: [PATCH] Handle entry title with double encoded entities in Atom feeds --- reader/atom/atom_10.go | 3 ++- reader/atom/atom_10_test.go | 54 ++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/reader/atom/atom_10.go b/reader/atom/atom_10.go index 5fb42d7b..6a64ae4f 100644 --- a/reader/atom/atom_10.go +++ b/reader/atom/atom_10.go @@ -6,6 +6,7 @@ package atom // import "miniflux.app/reader/atom" import ( "encoding/xml" + "html" "strconv" "strings" "time" @@ -235,5 +236,5 @@ func (a *atom10Text) String() string { content = a.Data } - return strings.TrimSpace(content) + return html.UnescapeString(strings.TrimSpace(content)) } diff --git a/reader/atom/atom_10_test.go b/reader/atom/atom_10_test.go index 519bb94b..9626d60f 100644 --- a/reader/atom/atom_10_test.go +++ b/reader/atom/atom_10_test.go @@ -265,7 +265,7 @@ func TestParseEntryTitleWithHTMLAndCDATA(t *testing.T) { t.Fatal(err) } - if feed.Entries[0].Title != "Test “Test”" { + if feed.Entries[0].Title != "Test “Test”" { t.Errorf("Incorrect entry title, got: %q", feed.Entries[0].Title) } } @@ -322,6 +322,58 @@ func TestParseEntryTitleWithXHTML(t *testing.T) { } } +func TestParseEntryTitleWithNumericCharacterReference(t *testing.T) { + data := ` + + Example Feed + + + + Σ ß + + urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a + 2003-12-13T18:30:02Z + Some text. + + + ` + + feed, err := Parse("https://example.org/", bytes.NewBufferString(data)) + if err != nil { + t.Fatal(err) + } + + if feed.Entries[0].Title != "Σ ß" { + t.Errorf("Incorrect entry title, got: %q", feed.Entries[0].Title) + } +} + +func TestParseEntryTitleWithDoubleEncodedEntities(t *testing.T) { + data := ` + + Example Feed + + + + 'AT&T' + + urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a + 2003-12-13T18:30:02Z + Some text. + + + ` + + feed, err := Parse("https://example.org/", bytes.NewBufferString(data)) + if err != nil { + t.Fatal(err) + } + + if feed.Entries[0].Title != `'AT&T'` { + t.Errorf("Incorrect entry title, got: %q", feed.Entries[0].Title) + } +} + func TestParseEntrySummaryWithXHTML(t *testing.T) { data := `