diff --git a/app/validators/strict_email_validator.rb b/app/validators/strict_email_validator.rb index ff6b2b019..7549aa23d 100644 --- a/app/validators/strict_email_validator.rb +++ b/app/validators/strict_email_validator.rb @@ -3,7 +3,11 @@ class StrictEmailValidator < ActiveModel::EachValidator # saying that it's quite permissive # but we want more, we want to ensure it's a domain with extension # so we append \.[A-Za-z]{2,} - REGEXP = /\A(?[^@[:space:]])+@(?[^@[:space:]\.])+(?\.[[:alnum:].]{2,})\z/ + TRUEMAIL_REGEX_DOMAIN = /[\p{L}0-9]+([-.]{1}[\p{L}\p{N}\p{Pd}]*[\p{L}\p{N}]+)*\.\p{L}{2,63}/i.freeze + TRUEMAIL_REGEX_EMAIL_PATTERN = %r{(?=\A.{6,255}\z)(\A([\p{L}0-9]+[\w\p{L}.+!~,'&%#*^`{}|\-/?=$]*)@(#{TRUEMAIL_REGEX_DOMAIN})\z)}.freeze + + REGEXP = TRUEMAIL_REGEX_EMAIL_PATTERN + DATE_SINCE_STRICT_EMAIL_VALIDATION = Date.parse(ENV.fetch('STRICT_EMAIL_VALIDATION_STARTS_ON')) rescue 0 def validate_each(record, attribute, value) diff --git a/spec/models/champs/email_champ_spec.rb b/spec/models/champs/email_champ_spec.rb index 359b9c0a5..4f89d26fc 100644 --- a/spec/models/champs/email_champ_spec.rb +++ b/spec/models/champs/email_champ_spec.rb @@ -60,6 +60,11 @@ describe Champs::EmailChamp do it { is_expected.to be_truthy } end + context 'when value includes accents' do + let(:value) { 'prenom.nom@etu.univ-rouen.fr' } + it { is_expected.to be_truthy } + end + context 'when value is the classic standard user@domain.ext' do let(:value) { 'username@mailserver.domain' } it { is_expected.to be_truthy }