Skip to content

Commit 66b96f9

Browse files
committed
add check in split for missing @ to avoid panic
1 parent 06ca3b2 commit 66b96f9

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

checkmail.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ func DialTimeout(addr string, timeout time.Duration) (*smtp.Client, error) {
117117

118118
func split(email string) (account, host string) {
119119
i := strings.LastIndexByte(email, '@')
120+
// If no @ present, not a valid email.
121+
if i < 0 {
122+
return
123+
}
120124
account = email[:i]
121125
host = email[i+1:]
122126
return

checkmail_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var (
2727
{mail: "é&ààà@gmail.com", format: false, account: false},
2828
{mail: "[email protected]", format: true, account: false},
2929
{mail: "[email protected]", format: true, account: false},
30+
{mail: "", format: false, account: false},
3031
}
3132
)
3233

0 commit comments

Comments
 (0)