Skip to content

Commit

Permalink
Chat monitor: Add Unicode support to regexes
Browse files Browse the repository at this point in the history
This should fix the issues with the filter thinking that `πŸΊβ„•π•šπ•Ÿπ•–π•₯𝕒𝕝𝕖𝕀-π”Έπ•π• π•π•’πŸΊ` was the T-slur.
  • Loading branch information
AnnikaCodes committed Dec 13, 2020
1 parent 4e0ae03 commit b7c3e6c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/chat-plugins/chat-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function constructEvasionRegex(str: string) {
const buf = "\\b" +
[...str].map(letter => (EVASION_DETECTION_SUB_STRINGS[letter] || letter) + '+').join('\\.?') +
"\\b";
return new RegExp(buf, 'i');
return new RegExp(buf, 'iu');
}

function renderEntry(location: string, word: Chat.FilterWord, punishment: string) {
Expand Down Expand Up @@ -102,7 +102,7 @@ export function generateRegex(word: string, isEvasion = false, isShortener = fal
if (isEvasion) {
return constructEvasionRegex(word);
} else {
return new RegExp((isShortener ? `\\b${word}` : word), (isReplacement ? 'ig' : 'i'));
return new RegExp((isShortener ? `\\b${word}` : word), (isReplacement ? 'igu' : 'iu'));
}
} catch (e) {
throw new Chat.ErrorMessage(
Expand Down Expand Up @@ -299,7 +299,7 @@ void FS(MONITOR_FILE).readIfExists().then(data => {
if (punishment === 'EVASION') {
regex = constructEvasionRegex(word);
} else {
regex = new RegExp(punishment === 'SHORTENER' ? `\\b${word}` : word, replacement ? 'ig' : 'i');
regex = new RegExp(punishment === 'SHORTENER' ? `\\b${word}` : word, replacement ? 'igu' : 'iu');
}

const filterWord: FilterWord = {regex, word, hits: parseInt(times) || 0};
Expand Down Expand Up @@ -445,7 +445,7 @@ export const nicknamefilter: NicknameFilter = (name, user) => {
// Evasion banwords by default require whitespace on either side.
// If we didn't remove it here, it would be quite easy to evade the filter
// and use slurs in PokΓ©mon nicknames.
regex = new RegExp(regex.toString().replace('/\\b', '').replace('\\b/i', ''), 'i');
regex = new RegExp(regex.toString().replace('/\\b', '').replace('\\b/i', ''), 'iu');
}

const match = regex.exec(lcName);
Expand Down

0 comments on commit b7c3e6c

Please sign in to comment.