BUGFIX: invalid referer would cause 500 errors

This commit is contained in:
Sam 2013-12-30 14:05:44 +11:00
parent 9738c4ff48
commit 1915f292ad
2 changed files with 12 additions and 2 deletions

View file

@ -18,8 +18,12 @@ class IncomingLink < ActiveRecord::Base
end
if request.referer.present?
begin
host = URI.parse(request.referer).host
referer = request.referer[0..999]
rescue URI::InvalidURIError
# bad uri, skip
end
end
if host != request.host && (user_id || referer)

View file

@ -62,6 +62,12 @@ describe IncomingLink do
IncomingLink.add(req('http://somesite.com', 'http://somesite.com'))
end
it "tracks visits for invalid referers" do
IncomingLink.add(req('http://somesite.com', 'bang bang bang'))
# no current user, don't track
IncomingLink.count.should == 0
end
it "expects to be called with referer and user id" do
IncomingLink.expects(:create).once.returns(true)
IncomingLink.add(req('http://somesite.com', 'http://some.other.site.com'), build(:user))