From 56707c0e4e20f4e217554d1cee2f4e1453d6b7ce Mon Sep 17 00:00:00 2001 From: Simperfy <28738855+Simperfy@users.noreply.github.com> Date: Wed, 14 Apr 2021 13:16:29 +0800 Subject: [PATCH 1/2] FIXED: error when sending symbols only in chat --- client/src/shared/state/Chat.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/src/shared/state/Chat.js b/client/src/shared/state/Chat.js index 4d9c631f..04dd79ec 100644 --- a/client/src/shared/state/Chat.js +++ b/client/src/shared/state/Chat.js @@ -68,10 +68,18 @@ class Chat { if (result === undefined) throw new Error(`Server returned an unknown scope: ${scope}`); } + isAlphaNumeric(str) { + return str.match("^[A-Za-z0-9]+$"); + } + 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.isAlphaNumeric(message)) { + return this.badWords.clean(message); + } } return message; From 7007eb095c07945863af81fb23c2b829702273d7 Mon Sep 17 00:00:00 2001 From: Simperfy <28738855+Simperfy@users.noreply.github.com> Date: Thu, 15 Apr 2021 16:00:08 +0800 Subject: [PATCH 2/2] FIXED: regex when checking for profanity --- client/src/shared/state/Chat.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/shared/state/Chat.js b/client/src/shared/state/Chat.js index 04dd79ec..bd07940a 100644 --- a/client/src/shared/state/Chat.js +++ b/client/src/shared/state/Chat.js @@ -68,8 +68,8 @@ class Chat { if (result === undefined) throw new Error(`Server returned an unknown scope: ${scope}`); } - isAlphaNumeric(str) { - return str.match("^[A-Za-z0-9]+$"); + isAlphaNumericSpace(str) { + return str.match("^[\\w\\s]+$"); } filterProfanity(message) { @@ -77,7 +77,7 @@ class Chat { if (this.guiState.profanityFilterEnabled) { // check if message contains letters or numbers to avoid error // https://github.com/web-mech/badwords/issues/103 - if (this.isAlphaNumeric(message)) { + if (this.isAlphaNumericSpace(message)) { return this.badWords.clean(message); } }