File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed
main/java/com/sanctionco/jmail
test/java/com/sanctionco/jmail Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -170,11 +170,16 @@ private static EmailValidationResult validateInternal(String email) {
170170 // email cannot start with '.'
171171 if (email .charAt (0 ) == '.' ) return EmailValidationResult .failure (FailureReason .STARTS_WITH_DOT );
172172
173- // email cannot end with '.' or '-'
174- if (email .charAt (size - 1 ) == '.' || email . charAt ( size - 1 ) == '-' ) {
173+ // email cannot end with '.'
174+ if (email .charAt (size - 1 ) == '.' ) {
175175 return EmailValidationResult .failure (FailureReason .ENDS_WITH_DOT );
176176 }
177177
178+ // email cannot end with '-'
179+ if (email .charAt (size - 1 ) == '-' ) {
180+ return EmailValidationResult .failure (FailureReason .DOMAIN_PART_ENDS_WITH_DASH );
181+ }
182+
178183 boolean atFound = false ; // set to true when the '@' character is found
179184 boolean inQuotes = false ; // set to true if we are currently within quotes
180185 boolean previousDot = false ; // set to true if the previous character is '.'
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ public static Stream<Arguments> provideTestEmails() {
1717 Arguments .of ("te[st@test.com" , FailureReason .DISALLOWED_UNQUOTED_CHARACTER ),
1818 Arguments .of ("test@" , FailureReason .DOMAIN_MISSING ),
1919 Arguments .of ("test@test-.com" , FailureReason .DOMAIN_PART_ENDS_WITH_DASH ),
20+ Arguments .of ("email@example.com-" , FailureReason .DOMAIN_PART_ENDS_WITH_DASH ),
2021 Arguments .of ("test@my.-test.com" , FailureReason .DOMAIN_PART_STARTS_WITH_DASH ),
2122 Arguments .of (
2223 "first.last@x234567890123456789012345678901234567890123456789012345678901234.test.org" ,
You can’t perform that action at this time.
0 commit comments