Defect #42584 » fix-email-address-domain_in-v2.patch
| app/models/email_address.rb | ||
|---|---|---|
|
# 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
|
||
| ... | ... | |
|
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?
|
||
| test/unit/email_address_test.rb | ||
|---|---|---|
|
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
|
||
- « Previous
- 1
- 2
- Next »