mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Remove trailing space in SiteURL and FeedURL
This commit is contained in:
parent
8e28e41b02
commit
fa9697b972
7 changed files with 274 additions and 22 deletions
|
@ -24,18 +24,18 @@ func NewRDFAdapter(rdf *RDF) *RDFAdapter {
|
|||
return &RDFAdapter{rdf}
|
||||
}
|
||||
|
||||
func (r *RDFAdapter) BuildFeed(feedURL string) *model.Feed {
|
||||
func (r *RDFAdapter) BuildFeed(baseURL string) *model.Feed {
|
||||
feed := &model.Feed{
|
||||
Title: stripTags(r.rdf.Channel.Title),
|
||||
FeedURL: feedURL,
|
||||
SiteURL: r.rdf.Channel.Link,
|
||||
FeedURL: strings.TrimSpace(baseURL),
|
||||
SiteURL: strings.TrimSpace(r.rdf.Channel.Link),
|
||||
}
|
||||
|
||||
if feed.Title == "" {
|
||||
feed.Title = feedURL
|
||||
feed.Title = baseURL
|
||||
}
|
||||
|
||||
if siteURL, err := urllib.AbsoluteURL(feedURL, r.rdf.Channel.Link); err == nil {
|
||||
if siteURL, err := urllib.AbsoluteURL(feed.FeedURL, feed.SiteURL); err == nil {
|
||||
feed.SiteURL = siteURL
|
||||
}
|
||||
|
||||
|
|
|
@ -289,7 +289,37 @@ func TestParseRDFFeedWithRelativeLink(t *testing.T) {
|
|||
xmlns="http://purl.org/rss/1.0/">
|
||||
<channel>
|
||||
<title>Example Feed</title>
|
||||
<link>/test/index.html</link>
|
||||
<link>/test/index.html </link>
|
||||
</channel>
|
||||
<item>
|
||||
<title>Example</title>
|
||||
<link>http://example.org/item</link>
|
||||
<description>Test</description>
|
||||
</item>
|
||||
</rdf:RDF>`
|
||||
|
||||
feed, err := Parse("http://example.org/feed", bytes.NewReader([]byte(data)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if feed.SiteURL != "http://example.org/test/index.html" {
|
||||
t.Errorf(`Incorrect SiteURL, got: %q`, feed.SiteURL)
|
||||
}
|
||||
|
||||
if feed.FeedURL != "http://example.org/feed" {
|
||||
t.Errorf(`Incorrect FeedURL, got: %q`, feed.FeedURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRDFFeedSiteURLWithTrailingSpace(t *testing.T) {
|
||||
data := `<?xml version="1.0" encoding="utf-8"?>
|
||||
<rdf:RDF
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns="http://purl.org/rss/1.0/">
|
||||
<channel>
|
||||
<title>Example Feed</title>
|
||||
<link>http://example.org/test/index.html </link>
|
||||
</channel>
|
||||
<item>
|
||||
<title>Example</title>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue