Permalink
Browse files

Fix RSS link parsing to use chardata instead

  • Loading branch information...
1 parent 30aba59 commit df3998c83413bbe763130a8079c3929d823bb819 @mjibson committed Dec 8, 2013
Showing with 27 additions and 3 deletions.
  1. +3 −3 rss/rss.go
  2. +24 −0 rss/rss_test.go
View
@@ -25,8 +25,8 @@ func (r *Rss) Hub() string {
func (r *Rss) BaseLink() string {
for _, l := range r.Link {
- if l.Rel == "" && l.Type == "" && l.Href == "" && l.InnerXML != "" {
- return l.InnerXML
+ if l.Rel == "" && l.Type == "" && l.Href == "" && l.Chardata != "" {
+ return l.Chardata
}
}
return ""
@@ -36,7 +36,7 @@ type Link struct {
Rel string `xml:"rel,attr"`
Href string `xml:"href,attr"`
Type string `xml:"type,attr"`
- InnerXML string `xml:",innerxml"`
+ Chardata string `xml:",chardata"`
}
type Item struct {
View
@@ -24,6 +24,30 @@ import (
"code.google.com/p/go-charset/charset"
)
+func TestCDATALink(t *testing.T) {
+ r := Rss{}
+ d := xml.NewDecoder(strings.NewReader(ATALSOFT_FEED))
+ d.CharsetReader = charset.NewReader
+ d.DefaultSpace = "DefaultSpace"
+ if err := d.Decode(&r); err != nil {
+ t.Fatal(err)
+ }
+ if r.BaseLink() != "http://www.atalasoft.com/blogs/blogsrss.aspx?rss=loufranco" {
+ t.Error("bad link", r.BaseLink())
+ }
+}
+
+const ATALSOFT_FEED = `
+<?xml version="1.0" encoding="utf-8"?><rss version="2.0">
+<channel>
+<title><![CDATA[Lou Franco]]></title>
+<link><![CDATA[http://www.atalasoft.com/blogs/blogsrss.aspx?rss=loufranco]]></link>
+<description><![CDATA[Lou Franco Atalasoft RSS]]></description>
+<language><![CDATA[en-US]]></language>
+</channel>
+</rss>
+`
+
func TestParseHub(t *testing.T) {
r := Rss{}
d := xml.NewDecoder(strings.NewReader(WP_FEED))

0 comments on commit df3998c

Please sign in to comment.