Adding helper function

post_title_char_count
Dessalines 2021-11-23 09:56:24 -05:00
parent eceed94cb9
commit c0d5d89424
1 changed files with 8 additions and 4 deletions

View File

@ -120,10 +120,14 @@ pub fn scrape_text_for_mentions(text: &str) -> Vec<MentionData> {
out.into_iter().unique().collect() out.into_iter().unique().collect()
} }
fn has_newline(name: &str) -> bool {
name.contains('\n')
}
pub fn is_valid_actor_name(name: &str, actor_name_max_length: usize) -> bool { pub fn is_valid_actor_name(name: &str, actor_name_max_length: usize) -> bool {
name.chars().count() <= actor_name_max_length name.chars().count() <= actor_name_max_length
&& VALID_ACTOR_NAME_REGEX.is_match(name) && VALID_ACTOR_NAME_REGEX.is_match(name)
&& !name.contains('\n') && !has_newline(name)
} }
// Can't do a regex here, reverse lookarounds not supported // Can't do a regex here, reverse lookarounds not supported
@ -132,15 +136,15 @@ pub fn is_valid_display_name(name: &str, actor_name_max_length: usize) -> bool {
&& !name.starts_with('\u{200b}') && !name.starts_with('\u{200b}')
&& name.chars().count() >= 3 && name.chars().count() >= 3
&& name.chars().count() <= actor_name_max_length && name.chars().count() <= actor_name_max_length
&& !name.contains('\n') && !has_newline(name)
} }
pub fn is_valid_matrix_id(matrix_id: &str) -> bool { pub fn is_valid_matrix_id(matrix_id: &str) -> bool {
VALID_MATRIX_ID_REGEX.is_match(matrix_id) && !matrix_id.contains('\n') VALID_MATRIX_ID_REGEX.is_match(matrix_id) && !has_newline(matrix_id)
} }
pub fn is_valid_post_title(title: &str) -> bool { pub fn is_valid_post_title(title: &str) -> bool {
VALID_POST_TITLE_REGEX.is_match(title) && !title.contains('\n') VALID_POST_TITLE_REGEX.is_match(title) && !has_newline(title)
} }
pub fn get_ip(conn_info: &ConnectionInfo) -> IpAddr { pub fn get_ip(conn_info: &ConnectionInfo) -> IpAddr {