fix: fix email verification regex & unittests (#139)

This commit is contained in:
Nishant Joshi
2022-12-13 21:39:25 +05:30
committed by GitHub
parent ae8869318b
commit 7f0d8e8286

View File

@ -12,7 +12,7 @@ pub fn validate_email(email: &str) -> CustomResult<(), ValidationError> {
#[deny(clippy::invalid_regex)] #[deny(clippy::invalid_regex)]
static EMAIL_REGEX: Lazy<Option<Regex>> = Lazy::new(|| { static EMAIL_REGEX: Lazy<Option<Regex>> = Lazy::new(|| {
match Regex::new( match Regex::new(
r"^(?i)[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$", r"^(?i)[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$",
) { ) {
Ok(regex) => Some(regex), Ok(regex) => Some(regex),
Err(error) => { Err(error) => {
@ -92,11 +92,9 @@ mod tests {
prop_assert!(validate_email(&email).is_err()); prop_assert!(validate_email(&email).is_err());
} }
// TODO: make maybe unit test working #[test]
// minimal failing input: email = "+@a" fn proptest_invalid_email(email in "[.+]@(.+)") {
// #[test] prop_assert!(validate_email(&email).is_err());
// fn proptest_invalid_email(email in "[.+]@(.+)") { }
// prop_assert!(validate_email(&email).is_err());
// }
} }
} }