1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-03-18 06:58:17 +00:00

Replace custom email normalization logic with Rails' normalizes method (#29208).

git-svn-id: https://svn.redmine.org/redmine/trunk@23064 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA 2024-09-20 01:58:08 +00:00
parent 1905b26683
commit 52deba3abf

View File

@ -36,21 +36,19 @@ class EmailAddress < ApplicationRecord
:if => Proc.new {|email| email.address_changed? && email.address.present?} :if => Proc.new {|email| email.address_changed? && email.address.present?}
validate :validate_email_domain, :if => proc {|email| email.address.present?} validate :validate_email_domain, :if => proc {|email| email.address.present?}
safe_attributes 'address' normalizes :address, with: lambda { |address|
normalized_address = address.to_s.strip
def address=(arg)
normalized_address = arg.to_s.strip
# Convert internationalized domain name (IDN) to Punycode
# e.g. 'marie@société.example' => 'marie@xn--socit-esab.example'
local_part, _at, domain = normalized_address.partition('@') local_part, _at, domain = normalized_address.partition('@')
if domain.present? 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) ascii_domain = Addressable::IDNA.to_ascii(domain)
normalized_address = "#{local_part}@#{ascii_domain}" normalized_address = "#{local_part}@#{ascii_domain}"
end end
normalized_address
}
write_attribute(:address, normalized_address) safe_attributes 'address'
end
def destroy def destroy
if is_default? if is_default?