From d2f8bc44ff9b71a6cfb211d8582d92c37518f40a Mon Sep 17 00:00:00 2001 From: naskya Date: Thu, 27 Jun 2024 09:37:17 +0900 Subject: [PATCH] add test for emoji validator --- fishctl/src/config/server.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/fishctl/src/config/server.rs b/fishctl/src/config/server.rs index 7cf4903..e0491bf 100644 --- a/fishctl/src/config/server.rs +++ b/fishctl/src/config/server.rs @@ -172,7 +172,10 @@ fn validate_emoji(value: &str) -> Result<(), ValidationError> { // check if `value` is a custom emoji // "+", "-", "_" are allowed in emoji shortcodes in Misskey variants // ref: - if value.len() > 2 { + if value.is_ascii() && value.len() > 2 { + if value.chars().nth(0).unwrap() != ':' || value.chars().last().unwrap() != ':' { + return error; + } if value[1..value.len() - 1] .chars() .all(|c| c.is_ascii_alphanumeric() || c == '+' || c == '-' || c == '_') @@ -183,3 +186,31 @@ fn validate_emoji(value: &str) -> Result<(), ValidationError> { error } + +#[cfg(test)] +mod test { + #[test] + fn validate_emoji() { + super::validate_emoji("⭐").unwrap(); + super::validate_emoji("👍").unwrap(); + super::validate_emoji("❤️").unwrap(); + super::validate_emoji("💜").unwrap(); + super::validate_emoji("🧛🏽").unwrap(); + super::validate_emoji("🧑‍🤝‍🧑").unwrap(); + super::validate_emoji(":ameow_attention:").unwrap(); + super::validate_emoji(":meow_peek:").unwrap(); + super::validate_emoji(":ABlobcatLonglong:").unwrap(); + super::validate_emoji(":ABlobcat++Longlong:").unwrap(); + super::validate_emoji(":ABlobcat-Longlong:").unwrap(); + + super::validate_emoji("⭐⭐").unwrap_err(); + super::validate_emoji("::").unwrap_err(); + super::validate_emoji("?").unwrap_err(); + super::validate_emoji(":?:").unwrap_err(); + super::validate_emoji(":ameow_attention:").unwrap_err(); + super::validate_emoji("").unwrap_err(); + super::validate_emoji("ABlobcat-Longlong:").unwrap_err(); + super::validate_emoji("ABlobcat-Longlong").unwrap_err(); + super::validate_emoji(":雨:").unwrap_err(); + } +}