From 0e13b3ca8ef7c44d72d04822c4885651f08c6f7f Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Mon, 29 Jan 2024 12:06:55 +0100 Subject: [PATCH] Handle a single qoute in local part of email Previously this would panic because it didn't consider email address where the local part was a single double qoute (DQUOTE). --- src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 61fe358..2569f64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -648,7 +648,8 @@ fn parse_local_part(part: &str) -> Result<(), Error> { } else if part.len() > LOCAL_PART_MAX_LENGTH { Error::LocalPartTooLong.into() } else if part.starts_with(DQUOTE) && part.ends_with(DQUOTE) { - if part.len() == 2 { + // <= to handle `part` = `"` (single quote). + if part.len() <= 2 { Error::LocalPartEmpty.into() } else { parse_quoted_local_part(&part[1..part.len() - 1]) @@ -1093,6 +1094,11 @@ mod tests { Error::LocalPartEmpty, Some("local-part is empty"), ); + expect( + "\"@example.com", + Error::LocalPartEmpty, + Some("local-part is empty"), + ); } #[test]