Remove regex, once_cell deps
This commit is contained in:
parent
7fa1407d76
commit
11841f91b8
@ -14,9 +14,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
diesel = { version = "1.4.3", optional = true }
|
||||
once_cell = "1.2.0"
|
||||
rand = "0.7.2"
|
||||
regex = "1.3.1"
|
||||
serde = "1.0.102"
|
||||
url = "2.1.0"
|
||||
|
||||
|
@ -7,8 +7,6 @@ use std::{
|
||||
|
||||
#[cfg(feature = "diesel")]
|
||||
use diesel::sql_types::Text;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use serde::{
|
||||
de::{Error as SerdeError, Unexpected, Visitor},
|
||||
Deserialize, Deserializer, Serialize, Serializer,
|
||||
@ -17,11 +15,6 @@ use url::Host;
|
||||
|
||||
use crate::{display, error::Error, generate_localpart, parse_id};
|
||||
|
||||
// See https://matrix.org/docs/spec/appendices#user-identifiers
|
||||
static USER_LOCALPART_PATTERN: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(r"\A[a-z0-9\-.=_/]+\z").expect("Failed to create user localpart regex.")
|
||||
});
|
||||
|
||||
/// A Matrix user ID.
|
||||
///
|
||||
/// A `UserId` is generated randomly or converted from a string slice, and can be converted back
|
||||
@ -124,7 +117,11 @@ impl<'a> TryFrom<&'a str> for UserId {
|
||||
let (localpart, host, port) = parse_id('@', user_id)?;
|
||||
let downcased_localpart = localpart.to_lowercase();
|
||||
|
||||
if !USER_LOCALPART_PATTERN.is_match(&downcased_localpart) {
|
||||
// See https://matrix.org/docs/spec/appendices#user-identifiers
|
||||
if downcased_localpart.bytes().any(|b| match b {
|
||||
b'0'..=b'9' | b'a'..=b'z' | b'-' | b'.' | b'=' | b'_' | b'/' => false,
|
||||
_ => true,
|
||||
}) {
|
||||
return Err(Error::InvalidCharacters);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user