From 522834a91f699aa528c236575d8ea42c2e8c1faa Mon Sep 17 00:00:00 2001 From: mohammad <mohammad.alayoub@mni.thm.de> Date: Mon, 14 Jun 2021 21:15:56 +0200 Subject: [PATCH] fix showing the question with profanity words always in lower case --- .../util/topic-cloud-admin.service.ts | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/app/services/util/topic-cloud-admin.service.ts b/src/app/services/util/topic-cloud-admin.service.ts index 0c895c36b..087b89e5d 100644 --- a/src/app/services/util/topic-cloud-admin.service.ts +++ b/src/app/services/util/topic-cloud-admin.service.ts @@ -76,23 +76,6 @@ export class TopicCloudAdminService { return this.blacklist.asObservable(); } - // TODO: Bug, returned string is always lowercase, case should not be changed - filterProfanityWords(str: string): string { - let questionWithProfanity = str; - this.profanityWords.concat(this.getCustomProfanityList()).map((word) => { - questionWithProfanity = questionWithProfanity - .toLowerCase() - .includes(word.toLowerCase()) - ? this.replaceString( - questionWithProfanity.toLowerCase(), - word.toLowerCase(), - this.generateCensoredWord(word.length) - ) - : questionWithProfanity; - }); - return questionWithProfanity; - } - getCustomProfanityList(): string[] { const list = localStorage.getItem(this.profanityKey); return list ? list.split(',') : []; @@ -190,8 +173,24 @@ export class TopicCloudAdminService { return tags; } + filterProfanityWords(str: string): string { + let questionWithProfanity = str; + this.profanityWords.concat(this.getCustomProfanityList()).map((word) => { + questionWithProfanity = questionWithProfanity + .toLowerCase() + .includes(word.toLowerCase()) + ? this.replaceString( + questionWithProfanity, + word, + this.generateCensoredWord(word.length) + ) + : questionWithProfanity; + }); + return questionWithProfanity; + } + private replaceString(str: string, search: string, replace: string) { - return str.split(search).join(replace); + return str.replace(new RegExp(search, 'gi'), replace); } private generateCensoredWord(count: number) { -- GitLab