Defect #44787 » 0001-Fix-exception-when-normalizing-an-email-address-with.patch
| app/models/email_address.rb | ||
|---|---|---|
|
normalizes :address, with: lambda { |address|
|
||
|
normalized_address = address.to_s.strip
|
||
|
# An address that is longer than the limit as entered is invalid.
|
||
|
# Leave it to the length validation without converting it.
|
||
|
return normalized_address if normalized_address.length > User::MAIL_LENGTH_LIMIT
|
||
|
local_part, _at, domain = normalized_address.partition('@')
|
||
|
if domain.present?
|
||
|
# Convert internationalized domain name (IDN) to Punycode
|
||
|
# e.g. 'marie@société.example' => 'marie@xn--socit-esab.example'
|
||
|
ascii_domain = Addressable::IDNA.to_ascii(domain)
|
||
|
normalized_address = "#{local_part}@#{ascii_domain}"
|
||
|
begin
|
||
|
ascii_domain = Addressable::IDNA.to_ascii(domain)
|
||
|
normalized_address = "#{local_part}@#{ascii_domain}"
|
||
|
rescue Addressable::IDNA::PunycodeBigOutput
|
||
|
# The domain has a label that is too long to convert. Leave the
|
||
|
# address as it is, so that the validation rejects it.
|
||
|
end
|
||
|
end
|
||
|
normalized_address
|
||
|
}
|
||
| test/unit/email_address_test.rb | ||
|---|---|---|
|
assert_equal 'marie@xn--socit-esab.example', email.address
|
||
|
assert email.valid?
|
||
|
end
|
||
|
def test_should_reject_idn_email_address_with_too_long_label
|
||
|
# Addressable::IDNA.to_ascii raises Addressable::IDNA::PunycodeBigOutput
|
||
|
# for this address
|
||
|
email = EmailAddress.new(address: "marie@#{'абвгдежзийклмнопрстуфхцчшщъыьэюя' * 7}.example")
|
||
|
assert_not email.valid?
|
||
|
end
|
||
|
end
|
||