From 246161838a580a0d954ad12ba216a50a42bca9e0 Mon Sep 17 00:00:00 2001 From: Aakash Thatte Date: Thu, 19 Dec 2024 23:34:48 +0530 Subject: [PATCH] improve regex --- src/json_schema/mod.rs | 2 ++ src/json_schema/types.rs | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/json_schema/mod.rs b/src/json_schema/mod.rs index 9b253e7..5517982 100644 --- a/src/json_schema/mod.rs +++ b/src/json_schema/mod.rs @@ -913,6 +913,8 @@ mod tests { "username@com", // TLD must have at least 2 characters "username@example,com", // invalid character in domain "username@.example.com", // leading dot in domain + "username@-example.com", // domain cannot start with a hyphen + "username@example-.com", // domain cannot end with a hyphen "username@example..com", // double dot in domain name "username@.example..com", // multiple errors in domain ] diff --git a/src/json_schema/types.rs b/src/json_schema/types.rs index 2d62084..b5835be 100644 --- a/src/json_schema/types.rs +++ b/src/json_schema/types.rs @@ -35,8 +35,7 @@ pub static DATE: &str = r#""(?:\d{4})-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0 pub static TIME: &str = r#""(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\\.[0-9]+)?(Z)?""#; pub static UUID: &str = r#""[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}""#; pub static URI: &str = r#"^(https?|ftp):\/\/([^\s:@]+(:[^\s:@]*)?@)?([a-zA-Z\d.-]+\.[a-zA-Z]{2,}|localhost)(:\d+)?(\/[^\s?#]*)?(\?[^\s#]*)?(#[^\s]*)?$|^urn:[a-zA-Z\d][a-zA-Z\d\-]{0,31}:[^\s]+$"#; -pub static EMAIL: &str = - r"^[A-Za-z0-9]+(?:[._%+-][A-Za-z0-9]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,63}$"; +pub static EMAIL: &str = r#"^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$"#; #[derive(Debug, PartialEq)] pub enum FormatType {