From aa16d090121c93921bde6dce14d17a7e2c91bfc0 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 7 Oct 2024 20:27:00 +0800 Subject: [PATCH] fix: dam should match string case insenstive --- internal/pkg/dam/dam.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/internal/pkg/dam/dam.go b/internal/pkg/dam/dam.go index 2c2ebe24..71957780 100644 --- a/internal/pkg/dam/dam.go +++ b/internal/pkg/dam/dam.go @@ -16,7 +16,6 @@ package dam import ( "regexp" - "strings" "unicode" "github.com/trim21/errgo" @@ -34,21 +33,21 @@ func New(c config.AppConfig) (Dam, error) { var cc Dam var err error if c.NsfwWord != "" { - cc.nsfwWord, err = regexp.Compile(c.NsfwWord) + cc.nsfwWord, err = regexp.Compile("(?i)" + c.NsfwWord) if err != nil { return Dam{}, errgo.Wrap(err, "nsfw_word") } } if c.DisableWords != "" { - cc.disableWord, err = regexp.Compile(c.DisableWords) + cc.disableWord, err = regexp.Compile("(?i)" + c.DisableWords) if err != nil { return Dam{}, errgo.Wrap(err, "disable_words") } } if c.BannedDomain != "" { - cc.bannedDomain, err = regexp.Compile(c.BannedDomain) + cc.bannedDomain, err = regexp.Compile("(?i)" + c.BannedDomain) if err != nil { return Dam{}, errgo.Wrap(err, "banned_domain") } @@ -65,8 +64,6 @@ func (d Dam) NeedReview(text string) bool { return false } - text = strings.ToLower(text) - return d.disableWord.MatchString(text) }