mirror of
https://github.com/meineerde/redmine.git
synced 2026-01-31 19:47:14 +00:00
NoMethodError when creating a user with an invalid email address and domain restrictions are enabled (#42584).
Patch by Go MAEDA (user:maeda). git-svn-id: https://svn.redmine.org/redmine/trunk@23666 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
38730e5b3c
commit
41ed48fd7d
@ -74,7 +74,7 @@ class EmailAddress < ApplicationRecord
|
||||
|
||||
# Returns true if domain belongs to domains list.
|
||||
def self.domain_in?(domain, domains)
|
||||
domain = domain.downcase
|
||||
domain = domain.to_s.downcase
|
||||
domains = domains.to_s.split(/[\s,]+/) unless domains.is_a?(Array)
|
||||
domains.reject(&:blank?).map(&:downcase).any? do |s|
|
||||
s.start_with?('.') ? domain.end_with?(s) : domain == s
|
||||
@ -150,6 +150,10 @@ class EmailAddress < ApplicationRecord
|
||||
|
||||
def validate_email_domain
|
||||
domain = address.partition('@').last
|
||||
# Skip domain validation if the email does not contain a domain part,
|
||||
# to avoid an incomplete error message like "domain not allowed ()"
|
||||
return if domain.empty?
|
||||
|
||||
return if self.class.valid_domain?(domain)
|
||||
|
||||
if User.current.logged?
|
||||
|
||||
@ -63,6 +63,12 @@ class EmailAddressTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_domain_in_should_not_raise_exception_when_domain_is_nil
|
||||
assert_nothing_raised do
|
||||
assert_not EmailAddress.domain_in?(nil, 'example.com')
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_reject_invalid_email
|
||||
assert_not EmailAddress.new(address: 'invalid,email@example.com').valid?
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user