Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix email validation #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix email validation mail.ParseAddress return an reformated email if …
…the format is not really an email (with a space after of before for example). A check was added to compare the input and the output from mail.ParseAddress.
  • Loading branch information
Surfoo committed Dec 4, 2020

Unverified

This user has not yet uploaded their public signing key.
commit 35e9aba7cf3600f614e5fa29698df52f44f1c9db
9 changes: 5 additions & 4 deletions keywords_optional.go
Original file line number Diff line number Diff line change
@@ -123,12 +123,13 @@ func isValidDate(date string) error {
// representation as defined by RFC 5322, section 3.4.1 [RFC5322].
// https://tools.ietf.org/html/rfc5322#section-3.4.1
func isValidEmail(email string) error {
// if !emailPattern.MatchString(email) {
// return fmt.Errorf("invalid email Format")
// }
if _, err := mail.ParseAddress(email); err != nil {
res, err := mail.ParseAddress(email)
if err != nil {
return fmt.Errorf("email address incorrectly Formatted: %s", err.Error())
}
if res.Address != email {
return fmt.Errorf("email address incorrectly Formatted: %s", email)
}
return nil
}

5 changes: 5 additions & 0 deletions testdata/draft2019-09/optional/format/email.json
Original file line number Diff line number Diff line change
@@ -12,6 +12,11 @@
"description": "an invalid e-mail address",
"data": "2962",
"valid": false
},
{
"description": "an invalid e-mail address",
"data": " [email protected]",
"valid": false
}
]
}
5 changes: 5 additions & 0 deletions testdata/draft3/optional/format.json
Original file line number Diff line number Diff line change
@@ -112,6 +112,11 @@
"description": "an invalid e-mail address",
"data": "2962",
"valid": false
},
{
"description": "an invalid e-mail address",
"data": " [email protected]",
"valid": false
}
]
},
5 changes: 5 additions & 0 deletions testdata/draft4/optional/format.json
Original file line number Diff line number Diff line change
@@ -164,6 +164,11 @@
"description": "an invalid e-mail address",
"data": "2962",
"valid": false
},
{
"description": "an invalid e-mail address",
"data": " [email protected]",
"valid": false
}
]
},
5 changes: 5 additions & 0 deletions testdata/draft6/optional/format.json
Original file line number Diff line number Diff line change
@@ -236,6 +236,11 @@
"description": "an invalid e-mail address",
"data": "2962",
"valid": false
},
{
"description": "an invalid e-mail address",
"data": " [email protected]",
"valid": false
}
]
},
5 changes: 5 additions & 0 deletions testdata/draft7/optional/format/email.json
Original file line number Diff line number Diff line change
@@ -12,6 +12,11 @@
"description": "an invalid e-mail address",
"data": "2962",
"valid": false
},
{
"description": "an invalid e-mail address",
"data": " [email protected]",
"valid": false
}
]
}