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(); + } +}