Feature #29208 » 29208.patch
app/models/email_address.rb | ||
---|---|---|
39 | 39 |
safe_attributes 'address' |
40 | 40 | |
41 | 41 |
def address=(arg) |
42 |
write_attribute(:address, arg.to_s.strip) |
|
42 |
normalized_address = arg.to_s.strip |
|
43 | ||
44 |
# Convert internationalized domain name (IDN) to Punycode |
|
45 |
# e.g. 'marie@société.example' => 'marie@xn--socit-esab.example' |
|
46 |
local_part, _at, domain = normalized_address.partition('@') |
|
47 |
if domain.present? |
|
48 |
ascii_domain = Addressable::IDNA.to_ascii(domain) |
|
49 |
normalized_address = "#{local_part}@#{ascii_domain}" |
|
50 |
end |
|
51 | ||
52 |
write_attribute(:address, normalized_address) |
|
43 | 53 |
end |
44 | 54 | |
45 | 55 |
def destroy |
test/unit/email_address_test.rb | ||
---|---|---|
68 | 68 |
def test_should_reject_invalid_email |
69 | 69 |
assert_not EmailAddress.new(address: 'invalid,email@example.com').valid? |
70 | 70 |
end |
71 | ||
72 |
def test_should_normalize_idn_email_address |
|
73 |
email = EmailAddress.new(address: 'marie@société.example') |
|
74 |
assert_equal 'marie@xn--socit-esab.example', email.address |
|
75 |
assert email.valid? |
|
76 |
end |
|
71 | 77 |
end |