From ed774c274a02c605c06d2c7584b3404f70887aa7 Mon Sep 17 00:00:00 2001 From: mattbr0wn Date: Thu, 21 Nov 2024 15:14:07 +0000 Subject: [PATCH] fix system generated bug --- internal/syntax/user.go | 1 + mailvalidate/email_syntax_test.go | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/syntax/user.go b/internal/syntax/user.go index 4bb5720..b804f4d 100644 --- a/internal/syntax/user.go +++ b/internal/syntax/user.go @@ -120,6 +120,7 @@ func hasMultipleNumericSegments(username string) bool { func isCommonNamePattern(username string) bool { namePatterns := []*regexp.Regexp{ regexp.MustCompile(`^[a-z]+\.[a-z]+\d{0,4}$`), // john.doe123 + regexp.MustCompile(`^[a-z]+\_[a-z]+\d{0,4}$`), // john.doe123 regexp.MustCompile(`^[a-z]+\.[a-z]\.[a-z]+$`), // john.m.doe regexp.MustCompile(`^[a-z]+\.[a-z]+\.[a-z]+$`), // john.michael.doe regexp.MustCompile(`^[a-z]+[a-z0-9]{0,4}$`), // johndoe, john123 diff --git a/mailvalidate/email_syntax_test.go b/mailvalidate/email_syntax_test.go index 9e11a2b..1d5baac 100644 --- a/mailvalidate/email_syntax_test.go +++ b/mailvalidate/email_syntax_test.go @@ -3,8 +3,9 @@ package mailvalidate_test import ( "testing" - "github.com/customeros/mailsherpa/mailvalidate" "github.com/stretchr/testify/assert" + + "github.com/customeros/mailsherpa/mailvalidate" ) func TestValidateEmailSyntax(t *testing.T) { @@ -80,6 +81,21 @@ func TestValidateEmailSyntax(t *testing.T) { expected: mailvalidate.SyntaxValidation{}, description: "Invalid email should return empty validation struct", }, + { + name: "Underscore Username", + email: "bob_smith@google.com", + expected: mailvalidate.SyntaxValidation{ + IsValid: true, + User: "bob_smith", + Domain: "google.com", + CleanEmail: "bob_smith@google.com", + IsRoleAccount: false, + IsFreeAccount: false, + IsSystemGenerated: false, + Error: "", + }, + description: "Underscores in username should be supported", + }, { name: "Mixed Case with Emoji Email", email: "Rob.Name😆@Gmail.com",