Skip to content

Commit

Permalink
Fix bug where metainspector would crash if no links found on the page
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeiniesta committed Aug 12, 2012
1 parent 03ead0d commit 80c68ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/meta_inspector/scraper.rb
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions spec/fixtures/empty_page.response
@@ -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>
6 changes: 6 additions & 0 deletions spec/metainspector_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 80c68ad

Please sign in to comment.