mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:13:47 +08:00
BUGFIX: invalid referer would cause 500 errors
This commit is contained in:
parent
9738c4ff48
commit
1915f292ad
|
@ -18,8 +18,12 @@ class IncomingLink < ActiveRecord::Base
|
|||
end
|
||||
|
||||
if request.referer.present?
|
||||
host = URI.parse(request.referer).host
|
||||
referer = request.referer[0..999]
|
||||
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 New Issue
Block a user