Merged r23666 from trunk to 5.1-stable (#42584).

git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@23682 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2025-04-19 06:38:17 +00:00
parent 4e0c05bfd4
commit 7d9cdc16ba
2 changed files with 11 additions and 1 deletions

View File

@@ -66,7 +66,7 @@ class EmailAddress < ActiveRecord::Base
# 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
@@ -142,6 +142,10 @@ class EmailAddress < ActiveRecord::Base
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?

View File

@@ -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