Fix name for description checker.

This commit is contained in:
Dessalines 2024-10-28 10:32:20 -04:00
parent 5143e0ec30
commit a99cbbf5bb
4 changed files with 15 additions and 11 deletions

View file

@ -36,7 +36,11 @@ use lemmy_utils::{
error::{LemmyErrorExt, LemmyErrorType, LemmyResult}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::{ utils::{
slurs::check_slurs, slurs::check_slurs,
validation::{is_valid_actor_name, is_valid_body_field, site_description_length_check}, validation::{
is_valid_actor_name,
is_valid_body_field,
site_or_community_description_length_check,
},
}, },
}; };
@ -66,7 +70,7 @@ pub async fn create_community(
let description = data.description.clone(); let description = data.description.clone();
if let Some(desc) = &description { if let Some(desc) = &description {
site_description_length_check(desc)?; site_or_community_description_length_check(desc)?;
check_slurs(desc, &slur_regex)?; check_slurs(desc, &slur_regex)?;
} }

View file

@ -34,8 +34,8 @@ use lemmy_utils::{
build_and_check_regex, build_and_check_regex,
check_site_visibility_valid, check_site_visibility_valid,
is_valid_body_field, is_valid_body_field,
site_description_length_check,
site_name_length_check, site_name_length_check,
site_or_community_description_length_check,
}, },
}, },
}; };
@ -167,7 +167,7 @@ fn validate_create_payload(local_site: &LocalSite, create_site: &CreateSite) ->
check_slurs(&create_site.name, &slur_regex)?; check_slurs(&create_site.name, &slur_regex)?;
if let Some(desc) = &create_site.description { if let Some(desc) = &create_site.description {
site_description_length_check(desc)?; site_or_community_description_length_check(desc)?;
check_slurs(desc, &slur_regex)?; check_slurs(desc, &slur_regex)?;
} }

View file

@ -40,8 +40,8 @@ use lemmy_utils::{
check_site_visibility_valid, check_site_visibility_valid,
check_urls_are_valid, check_urls_are_valid,
is_valid_body_field, is_valid_body_field,
site_description_length_check,
site_name_length_check, site_name_length_check,
site_or_community_description_length_check,
}, },
}, },
}; };
@ -219,7 +219,7 @@ fn validate_update_payload(local_site: &LocalSite, edit_site: &EditSite) -> Lemm
} }
if let Some(desc) = &edit_site.description { if let Some(desc) = &edit_site.description {
site_description_length_check(desc)?; site_or_community_description_length_check(desc)?;
check_slurs_opt(&edit_site.description, &slur_regex)?; check_slurs_opt(&edit_site.description, &slur_regex)?;
} }

View file

@ -191,8 +191,8 @@ pub fn site_name_length_check(name: &str) -> LemmyResult<()> {
) )
} }
/// Checks the site description length, the limit as defined in the DB. /// Checks the site / community description length, the limit as defined in the DB.
pub fn site_description_length_check(description: &str) -> LemmyResult<()> { pub fn site_or_community_description_length_check(description: &str) -> LemmyResult<()> {
max_length_check( max_length_check(
description, description,
SITE_DESCRIPTION_MAX_LENGTH, SITE_DESCRIPTION_MAX_LENGTH,
@ -368,8 +368,8 @@ mod tests {
is_valid_matrix_id, is_valid_matrix_id,
is_valid_post_title, is_valid_post_title,
is_valid_url, is_valid_url,
site_description_length_check,
site_name_length_check, site_name_length_check,
site_or_community_description_length_check,
BIO_MAX_LENGTH, BIO_MAX_LENGTH,
SITE_DESCRIPTION_MAX_LENGTH, SITE_DESCRIPTION_MAX_LENGTH,
SITE_NAME_MAX_LENGTH, SITE_NAME_MAX_LENGTH,
@ -537,14 +537,14 @@ mod tests {
#[test] #[test]
fn test_valid_site_description() { fn test_valid_site_description() {
assert!(site_description_length_check( assert!(site_or_community_description_length_check(
&(0..SITE_DESCRIPTION_MAX_LENGTH) &(0..SITE_DESCRIPTION_MAX_LENGTH)
.map(|_| 'A') .map(|_| 'A')
.collect::<String>() .collect::<String>()
) )
.is_ok()); .is_ok());
let invalid_result = site_description_length_check( let invalid_result = site_or_community_description_length_check(
&(0..SITE_DESCRIPTION_MAX_LENGTH + 1) &(0..SITE_DESCRIPTION_MAX_LENGTH + 1)
.map(|_| 'A') .map(|_| 'A')
.collect::<String>(), .collect::<String>(),