diff --git a/db/banned_slurs.txt b/db/banned_slurs.txt new file mode 100644 index 0000000000..1bb81205b5 --- /dev/null +++ b/db/banned_slurs.txt @@ -0,0 +1,8 @@ +# This file serves to remove racial slurs and epithets from usage with vocodes. +# There's probably more than this that we'll want to remove. +# I need to investigate. +fag +faggot +fags +nigger +niggers \ No newline at end of file diff --git a/src/buckets/bucket_path_unifier.rs b/src/buckets/bucket_path_unifier.rs index 927d8b887a..3fb2c9ec29 100644 --- a/src/buckets/bucket_path_unifier.rs +++ b/src/buckets/bucket_path_unifier.rs @@ -192,7 +192,7 @@ mod tests { fn test_tts_synthesizer_path() { let paths = get_instance(); assert_eq!(paths.tts_synthesizer_path("foobar").to_str().unwrap(), - "/test_path_synthesizers/f/o/o/foobar.pth"); + "/test_path_synthesizers/f/o/o/foobar.pt"); } #[test] diff --git a/src/http_server/endpoints/tts/enqueue_infer_tts.rs b/src/http_server/endpoints/tts/enqueue_infer_tts.rs index 83592a1fc2..7bbbafc9c5 100644 --- a/src/http_server/endpoints/tts/enqueue_infer_tts.rs +++ b/src/http_server/endpoints/tts/enqueue_infer_tts.rs @@ -19,6 +19,7 @@ use sqlx::error::DatabaseError; use sqlx::error::Error::Database; use sqlx::mysql::MySqlDatabaseError; use std::sync::Arc; +use crate::validations::check_for_slurs::contains_slurs; const NEW_USER_ROLE: &'static str = "new-user"; @@ -102,6 +103,10 @@ pub async fn infer_tts_handler( return Err(InferTtsError::BadInput(reason)); } + if contains_slurs(&inference_text) { + return Err(InferTtsError::BadInput("text contains slurs".to_string())); + } + // TODO(bt): CHECK DATABASE! let model_token = request.tts_model_token.to_string(); diff --git a/src/main.rs b/src/main.rs index 2c13864646..4501a51f42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ pub const RESERVED_USERNAMES : &'static str = include_str!("../db/reserved_usernames.txt"); pub const RESERVED_SUBSTRINGS : &'static str = include_str!("../db/reserved_usernames_including.txt"); +pub const BANNED_SLURS : &'static str = include_str!("../db/banned_slurs.txt"); pub mod buckets; pub mod common_queries; diff --git a/src/validations/check_for_slurs.rs b/src/validations/check_for_slurs.rs new file mode 100644 index 0000000000..c89f4b5245 --- /dev/null +++ b/src/validations/check_for_slurs.rs @@ -0,0 +1,39 @@ +use std::collections::HashSet; +use crate::BANNED_SLURS; + +pub fn contains_slurs(unparsed_text: &str) -> bool { + lazy_static! { + static ref BANNED_SLURS_SET : HashSet = BANNED_SLURS.lines() + .map(|line| line.trim()) + .filter(|line| !(line.starts_with("#") || line.is_empty())) + .map(|line| line.to_string()) + .collect::>(); + } + + for wordlike in unparsed_text.split_ascii_whitespace() { + if BANNED_SLURS_SET.contains(wordlike) { + return true; + } + } + + false +} + +#[cfg(test)] +mod tests { + use crate::validations::check_for_slurs::contains_slurs; + + #[test] + fn valid_text_passes() { + assert_eq!(contains_slurs(""), false); + assert_eq!(contains_slurs("this is a test."), false); + assert_eq!(contains_slurs("this\nis\na\ntest\n\n"), false); + assert_eq!(contains_slurs(" this is a test"), false); + } + + #[test] + fn text_with_slurs_fails() { + assert_eq!(contains_slurs("a sentence containing fag is banned"), true); + assert_eq!(contains_slurs("a\nsentence\ncontaining fags\nis banned"), true); + } +} diff --git a/src/validations/mod.rs b/src/validations/mod.rs index fa53768548..2b24d755b8 100644 --- a/src/validations/mod.rs +++ b/src/validations/mod.rs @@ -1,3 +1,4 @@ +pub mod check_for_slurs; pub mod model_uploads; pub mod passwords; pub mod username;