From: Felix Ableitner Date: Tue, 12 Jan 2021 15:32:38 +0000 (+0100) Subject: Shorten slur filter to avoid false positives (fixes #535) X-Git-Url: http://these/git/%22https:/www.exeterceilidhs.net/%7B%60%24%7BwebArchiveUrl%7D/save/static/git-logo.png?a=commitdiff_plain;h=15710a05958fb7e3ba7249ae6c928b54aac09e70;p=lemmy.git Shorten slur filter to avoid false positives (fixes #535) --- diff --git a/lemmy_utils/src/test.rs b/lemmy_utils/src/test.rs index fdca384f..aaa59bfa 100644 --- a/lemmy_utils/src/test.rs +++ b/lemmy_utils/src/test.rs @@ -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(())); diff --git a/lemmy_utils/src/utils.rs b/lemmy_utils/src/utils.rs index 2af010a8..b2a7c97e 100644 --- a/lemmy_utils/src/utils.rs +++ b/lemmy_utils/src/utils.rs @@ -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[\w.]+)@(?P[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)").unwrap();