FIX: handle bad user profile website
This commit is contained in:
parent
238a13643d
commit
33899664ce
|
@ -140,7 +140,10 @@ class UserProfile < ActiveRecord::Base
|
|||
allowed_domains = SiteSetting.user_website_domains_whitelist
|
||||
return if (allowed_domains.blank? || self.website.blank?)
|
||||
|
||||
domain = URI.parse(self.website).host
|
||||
domain = begin
|
||||
URI.parse(self.website).host
|
||||
rescue URI::InvalidURIError
|
||||
end
|
||||
self.errors.add :base, (I18n.t('user.website.domain_not_allowed', domains: allowed_domains.split('|').join(", "))) unless allowed_domains.split('|').include?(domain)
|
||||
end
|
||||
|
||||
|
|
|
@ -71,6 +71,13 @@ describe UserProfile do
|
|||
user_profile.website = "http://discourse.org"
|
||||
expect(user_profile).to be_valid
|
||||
end
|
||||
|
||||
it "doesn't blow up with an invalid URI" do
|
||||
SiteSetting.user_website_domains_whitelist = "discourse.org"
|
||||
|
||||
user_profile.website = 'user - https://forum.example.com/user'
|
||||
expect { user_profile.save! }.to raise_error(ActiveRecord::RecordInvalid)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'after save' do
|
||||
|
|
Loading…
Reference in New Issue