Merge pull request #1195 from initforthe/post-analyser-backtrace-fix

Post analyser backtrace fix
This commit is contained in:
Robin Ward 2013-07-16 07:34:54 -07:00
commit 75282576b9
2 changed files with 13 additions and 3 deletions

View File

@ -63,9 +63,14 @@ class PostAnalyzer
@linked_hosts = {}
raw_links.each do |u|
uri = URI.parse(u)
host = uri.host
@linked_hosts[host] ||= 1
begin
uri = URI.parse(u)
host = uri.host
@linked_hosts[host] ||= 1
rescue URI::InvalidURIError
# An invalid URI does not count as a raw link.
next
end
end
@linked_hosts
end

View File

@ -80,6 +80,11 @@ describe PostAnalyzer do
post_analyzer = PostAnalyzer.new(raw_three_links, default_topic_id)
post_analyzer.linked_hosts.should == {"discourse.org" => 1, "www.imdb.com" => 1}
end
it 'returns blank for ipv6 output' do
post_analyzer = PostAnalyzer.new('PING www.google.com(lb-in-x93.1e100.net) 56 data bytes', default_topic_id)
post_analyzer.linked_hosts.should be_blank
end
end
end