mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
BUGFIX: invalid referer would cause 500 errors
This commit is contained in:
parent
9738c4ff48
commit
1915f292ad
2 changed files with 12 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue