From 4f358aa0f3b1299378d677b02d36392e76848966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Fri, 30 Oct 2020 23:20:44 -0700 Subject: [PATCH] Do not escape HTML for Atom 1.0 text content during parsing Avoid encoding single quotes to HTML entities ('). Feed contents are sanitized after parsing. --- reader/atom/atom_10.go | 5 +--- reader/atom/atom_10_test.go | 59 ++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/reader/atom/atom_10.go b/reader/atom/atom_10.go index 4e49a8d4..25bdec37 100644 --- a/reader/atom/atom_10.go +++ b/reader/atom/atom_10.go @@ -6,7 +6,6 @@ package atom // import "miniflux.app/reader/atom" import ( "encoding/xml" - "html" "strconv" "strings" "time" @@ -221,10 +220,8 @@ func (a *atom10Text) String() string { switch { case a.Type == "xhtml": content = a.XML - case a.Type == "html": + default: content = a.Data - case a.Type == "text" || a.Type == "": - content = html.EscapeString(a.Data) } return strings.TrimSpace(content) diff --git a/reader/atom/atom_10_test.go b/reader/atom/atom_10_test.go index 1e763ca4..ad897440 100644 --- a/reader/atom/atom_10_test.go +++ b/reader/atom/atom_10_test.go @@ -359,7 +359,7 @@ func TestParseEntrySummaryWithPlainText(t *testing.T) { t.Fatal(err) } - if feed.Entries[0].Content != "<Some text.>" { + if feed.Entries[0].Content != "" { t.Errorf("Incorrect entry content, got: %s", feed.Entries[0].Content) } } @@ -599,6 +599,63 @@ func TestParseInvalidXml(t *testing.T) { } } +func TestParseTitleWithSingleQuote(t *testing.T) { + data := ` + + + ' or ’ + + + ` + + feed, err := Parse(bytes.NewBufferString(data)) + if err != nil { + t.Fatal(err) + } + + if feed.Title != "' or ’" { + t.Errorf(`Incorrect title, got: %q`, feed.Title) + } +} + +func TestParseTitleWithEncodedSingleQuote(t *testing.T) { + data := ` + + + Test's Blog + + + ` + + feed, err := Parse(bytes.NewBufferString(data)) + if err != nil { + t.Fatal(err) + } + + if feed.Title != "Test's Blog" { + t.Errorf(`Incorrect title, got: %q`, feed.Title) + } +} + +func TestParseTitleWithSingleQuoteAndHTMLType(t *testing.T) { + data := ` + + + O’Hara + + + ` + + feed, err := Parse(bytes.NewBufferString(data)) + if err != nil { + t.Fatal(err) + } + + if feed.Title != "O’Hara" { + t.Errorf(`Incorrect title, got: %q`, feed.Title) + } +} + func TestParseWithHTMLEntity(t *testing.T) { data := `