]> Untitled Git - lemmy.git/commitdiff
Shorten slur filter to avoid false positives (fixes #535)
authorFelix Ableitner <me@nutomic.com>
Tue, 12 Jan 2021 15:32:38 +0000 (16:32 +0100)
committerFelix Ableitner <me@nutomic.com>
Fri, 15 Jan 2021 16:31:14 +0000 (17:31 +0100)
lemmy_utils/src/test.rs
lemmy_utils/src/utils.rs

index fdca384f52b91f79f3338938bbbe12663118293d..aaa59bfa7aefcc6b0a0b229184e01080eb9b1541 100644 (file)
@@ -53,7 +53,7 @@ fn test_valid_post_title() {
 #[test]
 fn test_slur_filter() {
   let test =
-      "coons test dindu ladyboy tranny retardeds. Capitalized Niggerz. This is a bunch of other safe text.";
+      "faggot test kike tranny cocksucker retardeds. Capitalized Niggerz. This is a bunch of other safe text.";
   let slur_free = "No slurs here";
   assert_eq!(
       remove_slurs(&test),
@@ -63,13 +63,13 @@ fn test_slur_filter() {
 
   let has_slurs_vec = vec![
     "Niggerz",
-    "coons",
-    "dindu",
-    "ladyboy",
+    "cocksucker",
+    "faggot",
+    "kike",
     "retardeds",
     "tranny",
   ];
-  let has_slurs_err_str = "No slurs - Niggerz, coons, dindu, ladyboy, retardeds, tranny";
+  let has_slurs_err_str = "No slurs - Niggerz, cocksucker, faggot, kike, retardeds, tranny";
 
   assert_eq!(slur_check(test), Err(has_slurs_vec));
   assert_eq!(slur_check(slur_free), Ok(()));
index 2af010a8486b79dd7bb5080174234f0ada0c6335..b2a7c97e267d3a04d243403c70d801ce262ec9e4 100644 (file)
@@ -7,7 +7,7 @@ use regex::{Regex, RegexBuilder};
 
 lazy_static! {
 static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap();
-static ref SLUR_REGEX: Regex = RegexBuilder::new(r"(fag(g|got|tard)?|maricos?|cock\s?sucker(s|ing)?|\bn(i|1)g(\b|g?(a|er)?(s|z)?)\b|dindu(s?)|mudslime?s?|kikes?|mongoloids?|towel\s*heads?|\bspi(c|k)s?\b|\bchinks?|niglets?|beaners?|\bnips?\b|\bcoons?\b|jungle\s*bunn(y|ies?)|jigg?aboo?s?|\bpakis?\b|rag\s*heads?|gooks?|cunts?|bitch(es|ing|y)?|puss(y|ies?)|twats?|feminazis?|whor(es?|ing)|\bslut(s|t?y)?|\btr(a|@)nn?(y|ies?)|ladyboy(s?)|\b(b|re|r)tard(ed)?s?)").case_insensitive(true).build().unwrap();
+static ref SLUR_REGEX: Regex = RegexBuilder::new(r"(fag(g|got|tard)?\b|cock\s?sucker(s|ing)?|\bn(i|1)g(\b|g?(a|er)?(s|z)?)\b|mudslime?s?|kikes?|\bspi(c|k)s?\b|\bchinks?|gooks?|bitch(es|ing|y)?|whor(es?|ing)|\btr(a|@)nn?(y|ies?)|\b(b|re|r)tard(ed)?s?)").case_insensitive(true).build().unwrap();
 static ref USERNAME_MATCHES_REGEX: Regex = Regex::new(r"/u/[a-zA-Z][0-9a-zA-Z_]*").unwrap();
 // TODO keep this old one, it didn't work with port well tho
 // static ref MENTIONS_REGEX: Regex = Regex::new(r"@(?P<name>[\w.]+)@(?P<domain>[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)").unwrap();