From fa8431c5c6569a7ab7235152529e59393e3a82ae Mon Sep 17 00:00:00 2001 From: lf94 Date: Tue, 5 Apr 2022 21:22:06 -0400 Subject: [PATCH] Try to use outermost element text when title is empty --- reader/atom/atom_10.go | 10 ++++++++-- reader/atom/atom_10_test.go | 29 ++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/reader/atom/atom_10.go b/reader/atom/atom_10.go index 441f8a51..6a28c064 100644 --- a/reader/atom/atom_10.go +++ b/reader/atom/atom_10.go @@ -245,7 +245,12 @@ func (a *atom10Text) String() string { content = a.InnerXML } case a.Type == "xhtml": - content = a.XHTMLRootElement.InnerXML + var root = a.XHTMLRootElement + if root.XMLName.Local == "div" { + content = root.InnerXML + } else { + content = a.InnerXML + } default: content = a.CharData } @@ -254,5 +259,6 @@ func (a *atom10Text) String() string { } type atomXHTMLRootElement struct { - InnerXML string `xml:",innerxml"` + XMLName xml.Name `xml:"div"` + InnerXML string `xml:",innerxml"` } diff --git a/reader/atom/atom_10_test.go b/reader/atom/atom_10_test.go index a0ee192b..498bfadb 100644 --- a/reader/atom/atom_10_test.go +++ b/reader/atom/atom_10_test.go @@ -449,7 +449,34 @@ func TestParseEntryWithEmptyXHTMLTitle(t *testing.T) { } if feed.Entries[0].Title != `http://example.org/entry` { - t.Errorf("Incorrect entry title, got: %q", feed.Entries[1].Title) + t.Errorf("Incorrect entry title, got: %q", feed.Entries[0].Title) + } +} + +func TestParseEntryWithXHTMLTitleWithoutDiv(t *testing.T) { + data := ` + + Example Feed + + + + + test + + + 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[0].Title != `test` { + t.Errorf("Incorrect entry title, got: %q", feed.Entries[0].Title) } }