Fix whole word filter not working

This commit is contained in:
Zhiyuan Zheng 2022-02-10 23:09:40 +01:00
parent f96e9af7b9
commit 44d1f6fbed
1 changed files with 2 additions and 2 deletions

View File

@ -46,7 +46,7 @@ export const shouldFilter = ({
let shouldFilter = false
if (!ownAccount) {
const parser = new htmlparser2.Parser({
ontext (text: string) {
ontext: (text: string) => {
const checkFilter = (filter: Mastodon.Filter) => {
const escapedPhrase = filter.phrase.replace(
/[.*+?^${}()|[\]\\]/g,
@ -54,7 +54,7 @@ export const shouldFilter = ({
) // $& means the whole matched string
switch (filter.whole_word) {
case true:
if (new RegExp('\\b' + escapedPhrase + '\\b').test(text)) {
if (new RegExp('\\B' + escapedPhrase + '\\B').test(text)) {
shouldFilter = true
}
break