mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
lists banned words in the chat error message - fixes https://github.com/HabitRPG/habitica/issues/8812 (#8858)
* issue 8812 - added the list of bad words matched to the postChat error message. * issue 8812 - added the list of bad words matched to the postChat error message. * issue 8812 - some refactoring, fixed relevant tests, and lint rules refactor * small fix for unnecessary empty array * added test and did some small refactoring * lint error fix * issue 8812 - added the list of bad words matched to the postChat error message. * issue 8812 - some refactoring, fixed relevant tests, and lint rules refactor * small fix for unnecessary empty array * added test and did some small refactoring * lint error fix * add test to check the error message contains the banned words used * improve banned words test * issue 8812 - added the list of bad words matched to the postChat error message. * issue 8812 - some refactoring, fixed relevant tests, and lint rules refactor * small fix for unnecessary empty array * added test and did some small refactoring * lint error fix * issue 8812 - added the list of bad words matched to the postChat error message. * issue 8812 - some refactoring, fixed relevant tests, and lint rules refactor * add test to check the error message contains the banned words used * improve banned words test * merge with develop - aligned banned slurs check with banned words check
This commit is contained in:
committed by
Sabe Jones
parent
014a7197f0
commit
026014b8d6
18
website/server/libs/stringUtils.js
Normal file
18
website/server/libs/stringUtils.js
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
export function removePunctuationFromString (str) {
|
||||
return str.replace(/[.,\/#!@$%\^&;:{}=\-_`~()]/g, ' ');
|
||||
}
|
||||
|
||||
export function getMatchesByWordArray (str, wordsToMatch) {
|
||||
let matchedWords = [];
|
||||
let wordRegexs = wordsToMatch.map((word) => new RegExp(`\\b([^a-z]+)?${word.toLowerCase()}([^a-z]+)?\\b`));
|
||||
for (let i = 0; i < wordRegexs.length; i += 1) {
|
||||
let regEx = wordRegexs[i];
|
||||
let match = str.toLowerCase().match(regEx);
|
||||
if (match !== null && match[0] !== null) {
|
||||
let trimmedMatch = removePunctuationFromString(match[0]).trim();
|
||||
matchedWords.push(trimmedMatch);
|
||||
}
|
||||
}
|
||||
return matchedWords;
|
||||
}
|
||||
Reference in New Issue
Block a user