mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
* 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
19 lines
631 B
JavaScript
19 lines
631 B
JavaScript
|
|
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;
|
|
}
|