mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 12:23:46 +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
|
end
|
||||||
|
|
||||||
if request.referer.present?
|
if request.referer.present?
|
||||||
host = URI.parse(request.referer).host
|
begin
|
||||||
referer = request.referer[0..999]
|
host = URI.parse(request.referer).host
|
||||||
|
referer = request.referer[0..999]
|
||||||
|
rescue URI::InvalidURIError
|
||||||
|
# bad uri, skip
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if host != request.host && (user_id || referer)
|
if host != request.host && (user_id || referer)
|
||||||
|
|
|
@ -62,6 +62,12 @@ describe IncomingLink do
|
||||||
IncomingLink.add(req('http://somesite.com', 'http://somesite.com'))
|
IncomingLink.add(req('http://somesite.com', 'http://somesite.com'))
|
||||||
end
|
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
|
it "expects to be called with referer and user id" do
|
||||||
IncomingLink.expects(:create).once.returns(true)
|
IncomingLink.expects(:create).once.returns(true)
|
||||||
IncomingLink.add(req('http://somesite.com', 'http://some.other.site.com'), build(:user))
|
IncomingLink.add(req('http://somesite.com', 'http://some.other.site.com'), build(:user))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user