From ccb6435c1d824ff3b13a4820bf29ac9352941a23 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Thu, 1 Dec 2022 21:33:59 +0000 Subject: [PATCH] Relax honeypot check (fixes #2595) (#2596) Co-authored-by: Dessalines --- crates/api_common/src/utils.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index 3aaf1972..1e863e85 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -307,7 +307,7 @@ pub fn site_description_length_check(description: &str) -> Result<(), LemmyError /// Checks for a honeypot. If this field is filled, fail the rest of the function pub fn honeypot_check(honeypot: &Option) -> Result<(), LemmyError> { - if honeypot.is_some() { + if honeypot.is_some() && honeypot != &Some(String::new()) { Err(LemmyError::from_message("honeypot_fail")) } else { Ok(()) @@ -724,7 +724,7 @@ pub fn listing_type_with_site_default( #[cfg(test)] mod tests { - use crate::utils::password_length_check; + use crate::utils::{honeypot_check, password_length_check}; #[test] #[rustfmt::skip] @@ -734,4 +734,12 @@ mod tests { assert!(password_length_check("short").is_err()); assert!(password_length_check("looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong").is_err()); } + + #[test] + fn honeypot() { + assert!(honeypot_check(&None).is_ok()); + assert!(honeypot_check(&Some(String::new())).is_ok()); + assert!(honeypot_check(&Some("1".to_string())).is_err()); + assert!(honeypot_check(&Some("message".to_string())).is_err()); + } } -- 2.44.1