summaryrefslogtreecommitdiff
path: root/internal/gtsmodel/filter.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-09-16 14:00:23 +0200
committerLibravatar GitHub <noreply@github.com>2024-09-16 14:00:23 +0200
commitefd1a4f717afa83d3d3609f0d70e4da151a8dc9b (patch)
tree246ae4c12f86f8866e5299ae39ba5c1feba0bce4 /internal/gtsmodel/filter.go
parent[bugfix/chore] Always set the status sensitive if media + content-warning pre... (diff)
downloadgotosocial-efd1a4f717afa83d3d3609f0d70e4da151a8dc9b.tar.xz
[bugfix] Use better plaintext representation of status for filtering (#3301)
* [bugfix] Use better plaintext representation of status for filtering * add new deps to readme * lint * update tests * update regexes * address review comments * remove now unused xxhash * whoops, wrong logger * Merge branch 'main' into status_filtering_bugfix * put cache in caches struct * pain
Diffstat (limited to 'internal/gtsmodel/filter.go')
-rw-r--r--internal/gtsmodel/filter.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/internal/gtsmodel/filter.go b/internal/gtsmodel/filter.go
index e670e6fc0..95047a44f 100644
--- a/internal/gtsmodel/filter.go
+++ b/internal/gtsmodel/filter.go
@@ -20,6 +20,8 @@ package gtsmodel
import (
"regexp"
"time"
+
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// Filter stores a filter created by a local account.
@@ -61,14 +63,23 @@ type FilterKeyword struct {
// Compile will compile this FilterKeyword as a prepared regular expression.
func (k *FilterKeyword) Compile() (err error) {
- var wordBreak string
- if k.WholeWord != nil && *k.WholeWord {
- wordBreak = `\b`
+ var (
+ wordBreakStart string
+ wordBreakEnd string
+ )
+
+ if util.PtrOrZero(k.WholeWord) {
+ // Either word boundary or
+ // whitespace or start of line.
+ wordBreakStart = `(?:\b|\s|^)`
+ // Either word boundary or
+ // whitespace or end of line.
+ wordBreakEnd = `(?:\b|\s|$)`
}
// Compile keyword filter regexp.
quoted := regexp.QuoteMeta(k.Keyword)
- k.Regexp, err = regexp.Compile(`(?i)` + wordBreak + quoted + wordBreak)
+ k.Regexp, err = regexp.Compile(`(?i)` + wordBreakStart + quoted + wordBreakEnd)
return // caller is expected to wrap this error
}