Permalink
Browse files

Fix bug where metainspector would crash if no links found on the page

  • Loading branch information...
1 parent 03ead0d commit 80c68add2d0cd415f89d7d097f9378e890e56db9 @jaimeiniesta committed Aug 12, 2012
Showing with 24 additions and 1 deletion.
  1. +1 −1 lib/meta_inspector/scraper.rb
  2. +17 −0 spec/fixtures/empty_page.response
  3. +6 −0 spec/metainspector_spec.rb
@@ -149,7 +149,7 @@ def method_missing(method_name)
def parsed_links
@parsed_links ||= parsed_document.search("//a") \
.map {|link| link.attributes["href"] \
- .to_s.strip}.uniq rescue nil
+ .to_s.strip}.uniq rescue []
end
def parsed_images
@@ -0,0 +1,17 @@
+HTTP/1.1 200 OK
+Server: nginx/0.7.67
+Date: Fri, 18 Nov 2011 21:46:46 GMT
+Content-Type: text/html
+Connection: keep-alive
+Last-Modified: Mon, 14 Nov 2011 16:53:18 GMT
+Content-Length: 4987
+X-Varnish: 2000423390
+Age: 0
+Via: 1.1 varnish
+
+<html>
+ <head>
+ </head>
+ <body>
+ </body>
+</html>
@@ -16,6 +16,7 @@
FakeWeb.register_uri(:get, "http://www.youtube.com/watch?v=iaGSSrp49uc", :response => fixture_file("youtube.response"))
FakeWeb.register_uri(:get, "http://w3clove.com/faqs", :response => fixture_file("w3clove_faqs.response"))
FakeWeb.register_uri(:get, "https://twitter.com/w3clove", :response => fixture_file("twitter_w3clove.response"))
+ FakeWeb.register_uri(:get, "https://example.com/empty", :response => fixture_file("empty_page.response"))
describe 'Initialization' do
it 'should accept an URL with a scheme' do
@@ -164,6 +165,11 @@
"http://twitter.com/W3CLove",
"http://us4.campaign-archive1.com/home/?u=6af3ab69c286561d0f0f25671&id=04a0dab609" ]
end
+
+ it "should return empty array if no links found" do
+ m = MetaInspector.new('http://example.com/empty')
+ m.links.should == []
+ end
end
describe 'Non-HTTP links' do

0 comments on commit 80c68ad

Please sign in to comment.