Skip to content

Commit

Permalink
fix: Avoid raising exception for invalid path problems
Browse files Browse the repository at this point in the history
When the feed was not declared as iTunes and the summary method was
trieggered an Nokogiri error was raised, because the summary had an
undeclared namespace. We now avoid that and return nil.
  • Loading branch information
marceloboeira committed Jan 13, 2017
1 parent d5bbe05 commit 23cffea
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/house/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def item_attr(xpath, attribute = nil)
node.attr(attribute).value
end
end
rescue Nokogiri::XML::XPath::SyntaxError => e
nil
end
end
end
2 changes: 2 additions & 0 deletions lib/house/podcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def attr(xpath)
else
node.text
end
rescue Nokogiri::XML::XPath::SyntaxError => e
nil
end
end
end
1 change: 1 addition & 0 deletions spec/lib/house/podcast_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
podcast = House::Podcast.new("http://podcasts.example.com/valid_with_items_without_itunes.xml")
item = podcast.items.first
item.subtitle.should be_nil
item.summary.should be_nil
item.keywords.should be_empty
item.duration.should be_nil
end
Expand Down
19 changes: 10 additions & 9 deletions spec/test_data/valid_with_2_items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
<channel>
<title>Example Podcast</title>
<itunes:author>Example Author</itunes:author>
<link>http://podcasts.example.com</link>
<link>http://podcasts.example.com</link>
<itunes:explicit>no</itunes:explicit>
<itunes:subtitle>iTunes Example Subtitle</itunes:subtitle>
<itunes:owner>
<itunes:name>iTunes Example Owner</itunes:name>
<itunes:email>[email protected]</itunes:email>
<itunes:name>iTunes Example Owner</itunes:name>
<itunes:email>[email protected]</itunes:email>
</itunes:owner>
<image>
<url>http://podcasts.example.com/example2.jpg</url>
<title>Example Podcast</title>
<link>http://www.example.com</link>
<url>http://podcasts.example.com/example2.jpg</url>
<title>Example Podcast</title>
<link>http://www.example.com</link>
</image>
<itunes:link rel="image" type="video/jpeg" href="http://www.example.com/example.jpg">Example Podcast</itunes:link>
<itunes:category text="Music" />
<itunes:summary>iTunes Example Summary</itunes:summary>
<description>Can't get enough of the radioshow Tiësto's Club Life? Then subscribe to this podcast and get a weekly update on the favourite tracks of Tiësto! For more info about Tiësto please visit www.tiesto.com or club.bnn.nl</description>
<language>EN</language>
<description>Can't get enough of the radioshow Tiësto's Club Life? Then subscribe to this podcast and get a weekly update on the favourite tracks of Tiësto! For more info about Tiësto please visit www.tiesto.com or club.bnn.nl</description>
<language>EN</language>
<webmaster>[email protected]</webmaster>
<lastBuildDate>Mon, 28 May 2012 13:00:00 GMT</lastBuildDate>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/example" />
Expand All @@ -37,13 +37,14 @@

<itunes:link rel="image" type="video/jpeg" href="http://podcasts.example.com/example2.jpg">Podcast 2 Example Image</itunes:link>
<enclosure url="http://podcasts.example.com/example2.m4a" length="0" type="audio/mpeg" />
<feedburner:origEnclosureLink>http://tracks.example.com/example2.m4a</feedburner:origEnclosureLink>
<feedburner:origEnclosureLink>http://tracks.example.com/example2.m4a</feedburner:origEnclosureLink>
</item>
<item>
<pubDate>Mon, 23 March 1999 23:00:00 GMT</pubDate>
<title>Example Podcast 1</title>
<author>Example Author 1</author>
<itunes:author>Example Author 1</itunes:author>
<itunes:summary>iTunes Example Summary</itunes:summary>
<itunes:subtitle>Example Subtitle 1</itunes:subtitle>
<itunes:keywords>dance,david,electronica,guetta,house,podcast,radio,video</itunes:keywords>
<itunes:duration>1:01:11</itunes:duration>
Expand Down
2 changes: 1 addition & 1 deletion spec/test_data/valid_without_itunes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
<channel>
<title>Example Podcast</title>
<link>http://podcasts.example.com</link>
Expand Down

0 comments on commit 23cffea

Please sign in to comment.