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.
This commit is contained in:
Frédéric Guillot 2020-10-30 23:20:44 -07:00
parent 2f3708d40c
commit 4f358aa0f3
2 changed files with 59 additions and 5 deletions

View File

@ -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)

View File

@ -359,7 +359,7 @@ func TestParseEntrySummaryWithPlainText(t *testing.T) {
t.Fatal(err)
}
if feed.Entries[0].Content != "<Some text.>" {
if feed.Entries[0].Content != "<Some text.>" {
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 := `
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>' or </title>
<link href="http://example.org/"/>
</feed>
`
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 := `
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="html">Test&#39;s Blog</title>
<link href="http://example.org/"/>
</feed>
`
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 := `
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="html">OHara</title>
<link href="http://example.org/"/>
</feed>
`
feed, err := Parse(bytes.NewBufferString(data))
if err != nil {
t.Fatal(err)
}
if feed.Title != "OHara" {
t.Errorf(`Incorrect title, got: %q`, feed.Title)
}
}
func TestParseWithHTMLEntity(t *testing.T) {
data := `
<?xml version="1.0" encoding="utf-8"?>