Skip to content

Commit

Permalink
Fix RSS enclosure parsing (#218)
Browse files Browse the repository at this point in the history
* fix(rss): fix enclosure parsing, ignoring every child nodes, not only text

* feat: add unit test for issue #217
  • Loading branch information
sgodart committed Feb 7, 2024
1 parent e8b4fbb commit 38e4aa4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
16 changes: 9 additions & 7 deletions rss/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,16 @@ func (rp *Parser) parseEnclosure(p *xpp.XMLPullParser) (enclosure *Enclosure, er
enclosure.Length = p.Attribute("length")
enclosure.Type = p.Attribute("type")

// Ignore any enclosure text
_, err = p.NextText()
if err != nil {
return enclosure, err
}
// Ignore any enclosure tag
for {
_, err := p.Next()
if err != nil {
return enclosure, err
}

if err = p.Expect(xpp.EndTag, "enclosure"); err != nil {
return nil, err
if p.Event == xpp.EndTag && p.Name == "enclosure" {
break
}
}

return enclosure, nil
Expand Down
17 changes: 17 additions & 0 deletions testdata/parser/rss/issue_217_enclosure_children.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"items": [
{
"enclosure": {
"url": "http://example.org/enclosure.jpg",
"type": "image/jpeg"
},
"enclosures": [
{
"url": "http://example.org/enclosure.jpg",
"type": "image/jpeg"
}
]
}
],
"version": "2.0"
}
23 changes: 23 additions & 0 deletions testdata/parser/rss/issue_217_enclosure_children.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

<!--
Description: issue #217
-->
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<item>

<enclosure url="http://example.org/enclosure.jpg" type="image/jpeg">
<media:title>
<![CDATA[ <p>Enclosure test title</p> ]]>
</media:title>
<media:copyright>
<![CDATA[ Enclosure copyright ]]>
</media:copyright>
<media:credits>
<![CDATA[ Enclosure credits ]]>
</media:credits>
</enclosure>

</item>
</channel>
</rss>

0 comments on commit 38e4aa4

Please sign in to comment.