mirror of
https://github.com/miniflux/v2.git
synced 2025-08-16 18:01:37 +00:00
Try to use outermost element text when title is empty
This commit is contained in:
parent
ec2b911881
commit
fa8431c5c6
2 changed files with 36 additions and 3 deletions
|
@ -245,7 +245,12 @@ func (a *atom10Text) String() string {
|
||||||
content = a.InnerXML
|
content = a.InnerXML
|
||||||
}
|
}
|
||||||
case a.Type == "xhtml":
|
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:
|
default:
|
||||||
content = a.CharData
|
content = a.CharData
|
||||||
}
|
}
|
||||||
|
@ -254,5 +259,6 @@ func (a *atom10Text) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type atomXHTMLRootElement struct {
|
type atomXHTMLRootElement struct {
|
||||||
InnerXML string `xml:",innerxml"`
|
XMLName xml.Name `xml:"div"`
|
||||||
|
InnerXML string `xml:",innerxml"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -449,7 +449,34 @@ func TestParseEntryWithEmptyXHTMLTitle(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if feed.Entries[0].Title != `http://example.org/entry` {
|
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 := `<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
|
<title>Example Feed</title>
|
||||||
|
<link href="http://example.org/"/>
|
||||||
|
|
||||||
|
<entry>
|
||||||
|
<title type="xhtml">
|
||||||
|
test
|
||||||
|
</title>
|
||||||
|
<link href="http://example.org/entry"/>
|
||||||
|
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
||||||
|
<updated>2003-12-13T18:30:02Z</updated>
|
||||||
|
</entry>
|
||||||
|
|
||||||
|
</feed>`
|
||||||
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue