From 64f74ba3449c298e333797bb57ce1274b7a8ffd7 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 16 Nov 2026 14:09:00 +0200 Subject: [PATCH] Allow single character host labels in email addresses - Truemail email_pattern accepted only 2+ char host labels, rejecting smth@e.ee and smth@a.domain.ee - Allow 1 char labels at every level except TLD, which stays 2-63 letters Closes #2959 --- config/initializers/truemail.rb | 3 ++- test/interactions/email_check_test.rb | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config/initializers/truemail.rb b/config/initializers/truemail.rb index 7c5a4ceb7a..d207954005 100644 --- a/config/initializers/truemail.rb +++ b/config/initializers/truemail.rb @@ -8,7 +8,8 @@ # By default verifier domain based on verifier email # config.verifier_domain = 'internet.ee' - config.email_pattern = /\A(?=[\p{L}0-9!#$%&'*+\/=?^_{|}~-]*[\p{L}0-9])([\p{L}0-9!#$%&'*+\/=?^_{|}~-]+(?:\.[\p{L}0-9!#$%&'*+\/=?^_{|}~-]+)*)@(?i:(xn--)?(?:[\p{L}0-9][\p{L}0-9-]{0,61}[\p{L}0-9]\.)+[\p{L}]{2,63}|\[[\d.a-fA-F:]+\])\z/ + # Host labels may be 1 char (smth@e.ee, smth@a.domain.ee); TLD stays 2+ letters. + config.email_pattern = /\A(?=[\p{L}0-9!#$%&'*+\/=?^_{|}~-]*[\p{L}0-9])([\p{L}0-9!#$%&'*+\/=?^_{|}~-]+(?:\.[\p{L}0-9!#$%&'*+\/=?^_{|}~-]+)*)@(?i:(xn--)?(?:[\p{L}0-9](?:[\p{L}0-9-]{0,61}[\p{L}0-9])?\.)+[\p{L}]{2,63}|\[[\d.a-fA-F:]+\])\z/ # config.smtp_error_body_pattern = /regex_pattern/ diff --git a/test/interactions/email_check_test.rb b/test/interactions/email_check_test.rb index df980429da..9c17650e1a 100644 --- a/test/interactions/email_check_test.rb +++ b/test/interactions/email_check_test.rb @@ -15,6 +15,10 @@ def test_validates_regex_email_format 'hello.world@example.com', '_user.email@domain.com', '__user.email@domain.com', + 'smth@e.ee', + 'smth@a.domain.ee', + 'smth@sub.b.domain.ee', + 'smth@1.ee', ] valid_emails.each_with_index do |email, index| @@ -29,7 +33,11 @@ def test_validates_regex_email_format 'user.@domain.com', 'us"er@domain.com', 'user@domain..com', - '~@internet.ee' + '~@internet.ee', + 'smth@domain.e', + 'smth@a.domain.e', + 'smth@-.ee', + 'smth@a-.ee' ] invalid_emails.each do |email|