Skip to content

Commit

Permalink
Merge pull request #121 from Simperfy/fix/chat-profanity-filter
Browse files Browse the repository at this point in the history
[FIX] Error when sending symbols only in chat
  • Loading branch information
Arcanorum authored Apr 15, 2021
2 parents 1b2485e + 7007eb0 commit 587decf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client/src/shared/state/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,18 @@ class Chat {
if (result === undefined) throw new Error(`Server returned an unknown scope: ${scope}`);
}

isAlphaNumericSpace(str) {
return str.match("^[\\w\\s]+$");
}

filterProfanity(message) {
// filter profanity only if it is enabled in the settings
if (this.guiState.profanityFilterEnabled) {
return this.badWords.clean(message);
// check if message contains letters or numbers to avoid error
// https://github.com/web-mech/badwords/issues/103
if (this.isAlphaNumericSpace(message)) {
return this.badWords.clean(message);
}
}

return message;
Expand Down

0 comments on commit 587decf

Please sign in to comment.