From c9e0f0b3e42e51c5a9b3fe57ac1ffc005d525912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Fri, 4 Mar 2022 14:18:43 -0800 Subject: [PATCH] Do not fallback to InnerXML if XHTML title is empty --- reader/atom/atom_10.go | 9 +++---- reader/atom/atom_10_test.go | 51 ++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/reader/atom/atom_10.go b/reader/atom/atom_10.go index 71e7c697..4b45603b 100644 --- a/reader/atom/atom_10.go +++ b/reader/atom/atom_10.go @@ -227,6 +227,9 @@ type atom10Text struct { XHTMLRootElement atomXHTMLRootElement `xml:"http://www.w3.org/1999/xhtml div"` } +// Text: https://datatracker.ietf.org/doc/html/rfc4287#section-3.1.1.1 +// HTML: https://datatracker.ietf.org/doc/html/rfc4287#section-3.1.1.2 +// XHTML: https://datatracker.ietf.org/doc/html/rfc4287#section-3.1.1.3 func (a *atom10Text) String() string { var content string switch { @@ -237,11 +240,7 @@ func (a *atom10Text) String() string { content = a.InnerXML } case a.Type == "xhtml": - if a.XHTMLRootElement.InnerXML != "" { - content = a.XHTMLRootElement.InnerXML - } else { - content = a.InnerXML - } + content = a.XHTMLRootElement.InnerXML default: content = a.CharData } diff --git a/reader/atom/atom_10_test.go b/reader/atom/atom_10_test.go index 6aec8dbf..51381765 100644 --- a/reader/atom/atom_10_test.go +++ b/reader/atom/atom_10_test.go @@ -339,14 +339,6 @@ func TestParseEntryWithXHTMLTitle(t *testing.T) { Example Feed - - <code>Test</code> Test - - urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a - 2003-12-13T18:30:02Z - Some text. - - <div xmlns="http://www.w3.org/1999/xhtml"> @@ -366,11 +358,34 @@ func TestParseEntryWithXHTMLTitle(t *testing.T) { t.Fatal(err) } - if feed.Entries[0].Title != `<code>Test</code> Test` { - t.Errorf("Incorrect entry title, got: %q", feed.Entries[0].Title) + if feed.Entries[0].Title != `This is <b>XHTML</b> content.` { + t.Errorf("Incorrect entry title, got: %q", feed.Entries[1].Title) + } +} + +func TestParseEntryWithEmptyXHTMLTitle(t *testing.T) { + data := `<?xml version="1.0" encoding="utf-8"?> + <feed xmlns="http://www.w3.org/2005/Atom"> + <title>Example Feed + + + + + <div xmlns="http://www.w3.org/1999/xhtml"/> + + + urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a + 2003-12-13T18:30:02Z + + + ` + + feed, err := Parse("https://example.org/", bytes.NewBufferString(data)) + if err != nil { + t.Fatal(err) } - if feed.Entries[1].Title != `This is XHTML content.` { + if feed.Entries[0].Title != `http://example.org/entry` { t.Errorf("Incorrect entry title, got: %q", feed.Entries[1].Title) } } @@ -433,14 +448,6 @@ func TestParseEntryWithXHTMLSummary(t *testing.T) { Example Feed - - Example - - urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a - 2003-12-13T18:30:02Z -

Some text.

-
- Example @@ -456,11 +463,7 @@ func TestParseEntryWithXHTMLSummary(t *testing.T) { t.Fatal(err) } - if feed.Entries[0].Content != `

Some text.

` { - t.Errorf("Incorrect entry content, got: %s", feed.Entries[0].Content) - } - - if feed.Entries[1].Content != `

Test: std::unique_ptr<S>

` { + if feed.Entries[0].Content != `

Test: std::unique_ptr<S>

` { t.Errorf("Incorrect entry content, got: %s", feed.Entries[1].Content) } }