diff options
author | Frédéric Guillot <fred@miniflux.net> | 2020-01-04 15:18:24 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2020-01-04 15:54:16 -0800 |
commit | bf632fad2e19e9ece4db5957f05727f373541917 (patch) | |
tree | 34c8f90d920f55892c10a25bba47f07c580dfe74 /reader/atom | |
parent | 8cebd985a267f6fbcc363672ca81780dd5407eff (diff) |
Allow only absolute URLs in comments URL
Some feeds are using invalid URLs (random text).
Diffstat (limited to 'reader/atom')
-rw-r--r-- | reader/atom/atom_10.go | 11 | ||||
-rw-r--r-- | reader/atom/atom_10_test.go | 40 |
2 files changed, 50 insertions, 1 deletions
diff --git a/reader/atom/atom_10.go b/reader/atom/atom_10.go index 099cbed..708cc9f 100644 --- a/reader/atom/atom_10.go +++ b/reader/atom/atom_10.go @@ -84,7 +84,7 @@ func (a *atom10Entry) Transform() *model.Entry { entry.Content = a.entryContent() entry.Title = a.entryTitle() entry.Enclosures = a.entryEnclosures() - entry.CommentsURL = a.Links.firstLinkWithRelationAndType("replies", "text/html") + entry.CommentsURL = a.entryCommentsURL() return entry } @@ -194,6 +194,15 @@ func (a *atom10Entry) entryEnclosures() model.EnclosureList { return enclosures } +// See https://tools.ietf.org/html/rfc4685#section-3 +func (a *atom10Entry) entryCommentsURL() string { + commentsURL := a.Links.firstLinkWithRelationAndType("replies", "text/html") + if url.IsAbsoluteURL(commentsURL) { + return commentsURL + } + return "" +} + type atom10Text struct { Type string `xml:"type,attr"` Data string `xml:",chardata"` diff --git a/reader/atom/atom_10_test.go b/reader/atom/atom_10_test.go index 63127c4..d614691 100644 --- a/reader/atom/atom_10_test.go +++ b/reader/atom/atom_10_test.go @@ -777,3 +777,43 @@ func TestParseRepliesLinkRelation(t *testing.T) { t.Errorf("Incorrect entry comments URL, got: %s", feed.Entries[0].CommentsURL) } } + +func TestAbsoluteCommentsURL(t *testing.T) { + data := `<?xml version="1.0" encoding="utf-8"?> + <feed xmlns="http://www.w3.org/2005/Atom" + xmlns:thr="http://purl.org/syndication/thread/1.0"> + <id>http://www.example.org/myfeed</id> + <title>My Example Feed</title> + <updated>2005-07-28T12:00:00Z</updated> + <link href="http://www.example.org/myfeed" /> + <author><name>James</name></author> + <entry> + <id>tag:entries.com,2005:1</id> + <title>My original entry</title> + <updated>2006-03-01T12:12:12Z</updated> + <link href="http://www.example.org/entries/1" /> + <link rel="replies" + type="text/html" + href="invalid url" + thr:count="10" thr:updated="2005-07-28T12:10:00Z" /> + <summary>This is my original entry</summary> + </entry> + </feed>` + + feed, err := Parse(bytes.NewBufferString(data)) + if err != nil { + t.Fatal(err) + } + + if len(feed.Entries) != 1 { + t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries)) + } + + if feed.Entries[0].URL != "http://www.example.org/entries/1" { + t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL) + } + + if feed.Entries[0].CommentsURL != "" { + t.Errorf("Incorrect entry comments URL, got: %s", feed.Entries[0].CommentsURL) + } +} |