email::send_email,
location_info,
settings::structs::Settings,
- utils::{generate_random_string, is_valid_display_name, naive_from_unix},
+ utils::{generate_random_string, is_valid_display_name, is_valid_matrix_id, naive_from_unix},
ApiError,
ConnectionId,
LemmyError,
}
}
+ if let Some(Some(matrix_user_id)) = &matrix_user_id {
+ if !is_valid_matrix_id(matrix_user_id) {
+ return Err(ApiError::err("invalid_matrix_id").into());
+ }
+ }
+
let local_user_id = local_user_view.local_user.id;
let person_id = local_user_view.person.id;
let default_listing_type = data.default_listing_type;
use crate::utils::{
is_valid_community_name,
is_valid_display_name,
+ is_valid_matrix_id,
is_valid_post_title,
is_valid_username,
remove_slurs,
assert!(!is_valid_post_title("\n \n \n \n ")); // tabs/spaces/newlines
}
+#[test]
+fn test_valid_matrix_id() {
+ assert!(is_valid_matrix_id("@dess:matrix.org"));
+ assert!(!is_valid_matrix_id("dess:matrix.org"));
+ assert!(!is_valid_matrix_id(" @dess:matrix.org"));
+ assert!(!is_valid_matrix_id("@dess:matrix.org t"));
+}
+
#[test]
fn test_slur_filter() {
let test =
static ref VALID_USERNAME_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9_]{3,20}$").expect("compile regex");
static ref VALID_COMMUNITY_NAME_REGEX: Regex = Regex::new(r"^[a-z0-9_]{3,20}$").expect("compile regex");
static ref VALID_POST_TITLE_REGEX: Regex = Regex::new(r".*\S.*").expect("compile regex");
+ static ref VALID_MATRIX_ID_REGEX: Regex = Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex");
}
pub fn naive_from_unix(time: i64) -> NaiveDateTime {
&& name.chars().count() <= 20
}
+pub fn is_valid_matrix_id(matrix_id: &str) -> bool {
+ VALID_MATRIX_ID_REGEX.is_match(matrix_id)
+}
+
pub fn is_valid_community_name(name: &str) -> bool {
VALID_COMMUNITY_NAME_REGEX.is_match(name)
}