Defect #42584 » fix-email-address-domain_in-v2.patch
| app/models/email_address.rb | ||
|---|---|---|
| 74 | 74 | |
| 75 | 75 |
# Returns true if domain belongs to domains list. |
| 76 | 76 |
def self.domain_in?(domain, domains) |
| 77 |
domain = domain.downcase |
|
| 77 |
domain = domain.to_s.downcase
|
|
| 78 | 78 |
domains = domains.to_s.split(/[\s,]+/) unless domains.is_a?(Array) |
| 79 | 79 |
domains.reject(&:blank?).map(&:downcase).any? do |s| |
| 80 | 80 |
s.start_with?('.') ? domain.end_with?(s) : domain == s
|
| ... | ... | |
| 150 | 150 | |
| 151 | 151 |
def validate_email_domain |
| 152 | 152 |
domain = address.partition('@').last
|
| 153 |
# Skip domain validation if the email does not contain a domain part, |
|
| 154 |
# to avoid an incomplete error message like "domain not allowed ()" |
|
| 155 |
return if domain.empty? |
|
| 156 | ||
| 153 | 157 |
return if self.class.valid_domain?(domain) |
| 154 | 158 | |
| 155 | 159 |
if User.current.logged? |
| test/unit/email_address_test.rb | ||
|---|---|---|
| 63 | 63 |
end |
| 64 | 64 |
end |
| 65 | 65 | |
| 66 |
def test_domain_in_should_not_raise_exception_when_domain_is_nil |
|
| 67 |
assert_nothing_raised do |
|
| 68 |
assert_not EmailAddress.domain_in?(nil, 'example.com') |
|
| 69 |
end |
|
| 70 |
end |
|
| 71 | ||
| 66 | 72 |
def test_should_reject_invalid_email |
| 67 | 73 |
assert_not EmailAddress.new(address: 'invalid,email@example.com').valid? |
| 68 | 74 |
end |
- « Previous
- 1
- 2
- Next »