truffle-hog 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/truffle-hog.rb +7 -2
- data/spec/truffle-hog_spec.rb +5 -1
- metadata +1 -1
data/lib/truffle-hog.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module TruffleHog
|
2
|
-
VERSION = "0.0.
|
2
|
+
VERSION = "0.0.3"
|
3
3
|
|
4
4
|
def self.parse_feed_urls(html, favor = :all)
|
5
5
|
rss_links = scan_for_tag(html, "rss")
|
@@ -23,7 +23,12 @@ module TruffleHog
|
|
23
23
|
tags = html.scan(/(<#{tag}.*?>)/).flatten
|
24
24
|
feed_tags = collect(tags, type)
|
25
25
|
feed_tags.map do |tag|
|
26
|
-
|
26
|
+
matches = tag.match(/.*href=['"](.*?)['"].*/)
|
27
|
+
if matches.nil?
|
28
|
+
url = ""
|
29
|
+
else
|
30
|
+
url = matches[1]
|
31
|
+
end
|
27
32
|
url =~ /^http.*/ ? url : nil
|
28
33
|
end.compact
|
29
34
|
end
|
data/spec/truffle-hog_spec.rb
CHANGED
@@ -39,11 +39,15 @@ describe "parsing html" do
|
|
39
39
|
it "returns atom feeds if rss is favored, but none are found"
|
40
40
|
it "returns rss feeds if atom is favored, but none are found"
|
41
41
|
|
42
|
-
describe "
|
42
|
+
describe "regressions" do
|
43
43
|
it "doesn't go into an infinite loop on this input" do
|
44
44
|
input = File.read("#{File.dirname(__FILE__)}/infinite.html")
|
45
45
|
feed_urls = TruffleHog.parse_feed_urls(input)
|
46
46
|
feed_urls.should == ["http://feeds.feedburner.com/cryptload"]
|
47
47
|
end
|
48
|
+
|
49
|
+
it "doesn't break when an anchor without an href is passed" do
|
50
|
+
TruffleHog.parse_feed_urls("<a type='application/rss+xml'>").should == []
|
51
|
+
end
|
48
52
|
end
|
49
53
|
end
|