diff --git a/src/json_schema/mod.rs b/src/json_schema/mod.rs index 136bb9b..9b253e7 100644 --- a/src/json_schema/mod.rs +++ b/src/json_schema/mod.rs @@ -899,27 +899,25 @@ mod tests { r#"{"title": "Bar", "type": "string", "format": "email"}"#, EMAIL, vec![ - "user@example.com", - "user.name+tag+sorting@example.com", - "user_name@example.co.uk", - "user-name@sub.example.com", - "user@123.123.123.123", - "user@[IPv6:2001:db8::1]", + // Valid emails + "user@example.com", // valid + "user.name+tag+sorting@example.com", // valid + "user_name@example.co.uk", // valid + "user-name@sub.example.com", // valid ], vec![ - "plainaddress", // missing '@' and domain - "@missingusername.com", // missing username - "username@.com", // missing domain name - "username@com", // TLD must have at least 2 characters - "username@example,com", // invalid character in domain - "username@.example.com", // leading dot in domain is invalid - "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 - "username@123.123.123.12345", // invalid IP format + // Invalid emails + "plainaddress", // missing '@' and domain + "@missingusername.com", // missing username + "username@.com", // leading dot in domain + "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", // double dot in domain name + "username@.example..com", // multiple errors in domain ] - ), + ) + ] { let json: Value = serde_json::from_str(schema).expect("Can't parse json"); let result = to_regex(&json, None).expect("To regex failed"); diff --git a/src/json_schema/types.rs b/src/json_schema/types.rs index db3f062..2d62084 100644 --- a/src/json_schema/types.rs +++ b/src/json_schema/types.rs @@ -35,7 +35,8 @@ 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-Z]{2,}$"; +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}$"; #[derive(Debug, PartialEq)] pub enum FormatType {