mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Add checks for profanity to profile updates (#12445)
* fix(profile): detect attempt to use banned words as display name. refactor profanity detection method. * fix(profile): detect attempt to use banned words in blurb. further refactor profanity detection. inform the user their chat privileges have been revoked. * refactor: add function to normalize Unicode strings and remove diacritics * fix: improve regEx to prevent false partial matches e.g. 'hello' being recognised as banned words. porting fix from #12309 * fix(profile): refactor of profanity detection for #12445 * fix(profile): add test for swear words in new profile. fix existing tests * fix(profile): show different error message for attempted slur use in username by new users. * fix(profile): remove incorrect slur test * fix(profile): fix slurs not caught at start of end of strings connect by punctuation * tests(profile): fix tests for profanity checking * remove exclusive test * 11865 - update text for slur warnings * 11865 - remove unused string from locale files * 11865 - improve naming of banned word usage locale string * 11865 - improve logic so that differentiated warnings are shown depending on whether a slur or other profanity has been used in a display name * 11865 - construct slur regexes outside the validation function in which they are used * 11865 - fix tests
This commit is contained in:
committed by
GitHub
parent
4d7304ab8d
commit
a53355872b
@@ -1,3 +1,7 @@
|
||||
export function normalizeUnicodeString (str) {
|
||||
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
||||
}
|
||||
|
||||
export function removePunctuationFromString (str) {
|
||||
return str.replace(/[.,/#!@$%^&;:{}=\-_`~()]/g, ' ');
|
||||
}
|
||||
@@ -12,15 +16,16 @@ export function getMatchesByWordArray (str, wordsToMatch) {
|
||||
// https://www.unicode.org/reports/tr15/#Canon_Compat_Equivalence
|
||||
// https://unicode-table.com/en/#combining-diacritical-marks
|
||||
|
||||
const normalizedStr = str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
||||
|
||||
const matchedWords = [];
|
||||
const wordRegexs = wordsToMatch.map(word => new RegExp(`\\b([^a-z]+)?${word}([^a-z]+)?\\b`, 'i'));
|
||||
const wordRegexs = wordsToMatch.map(word => {
|
||||
const normalizedWord = removePunctuationFromString(normalizeUnicodeString(word));
|
||||
return new RegExp(`\\b([^a-z]+)?${normalizedWord}([^a-z]+)?\\b`, 'i');
|
||||
});
|
||||
for (let i = 0; i < wordRegexs.length; i += 1) {
|
||||
const regEx = wordRegexs[i];
|
||||
const match = normalizedStr.match(regEx);
|
||||
const match = removePunctuationFromString(normalizeUnicodeString(str)).match(regEx);
|
||||
if (match !== null && match[0] !== null) {
|
||||
const trimmedMatch = removePunctuationFromString(match[0]).trim();
|
||||
const trimmedMatch = match[0].trim();
|
||||
matchedWords.push(trimmedMatch);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user