all repos — honk @ b9ac7da77508eff8ddb6b495729d8417a957bd27

my fork of honk

don't word bound regexp that don't have word endings
Ted Unangst tedu@tedunangst.com
Mon, 11 Jan 2021 21:12:19 -0500
commit

b9ac7da77508eff8ddb6b495729d8417a957bd27

parent

21de784d7b26344db6bfe2c1e35dda0be89f867d

1 files changed, 23 insertions(+), 4 deletions(-)

jump to
M hfcs.gohfcs.go

@@ -21,6 +21,7 @@ "net/http"

"regexp" "sort" "time" + "unicode" "humungus.tedunangst.com/r/webs/cache" )

@@ -108,15 +109,33 @@ if expflush.IsZero() || filt.Expiration.Before(expflush) {

expflush = filt.Expiration } } - if filt.Text != "" { - filt.re_text, err = regexp.Compile("\\b(?i:" + filt.Text + ")\\b") + if t := filt.Text; t != "" { + wordfront := unicode.IsLetter(rune(t[0])) + wordtail := unicode.IsLetter(rune(t[len(t)-1])) + t = "(?i:" + t + ")" + if wordfront { + t = "\\b" + t + } + if wordtail { + t = t + "\\b" + } + filt.re_text, err = regexp.Compile(t) if err != nil { log.Printf("error compiling filter text: %s", err) continue } } - if filt.Rewrite != "" { - filt.re_rewrite, err = regexp.Compile("\\b(?i:" + filt.Rewrite + ")\\b") + if t := filt.Rewrite; t != "" { + wordfront := unicode.IsLetter(rune(t[0])) + wordtail := unicode.IsLetter(rune(t[len(t)-1])) + t = "(?i:" + t + ")" + if wordfront { + t = "\\b" + t + } + if wordtail { + t = t + "\\b" + } + filt.re_rewrite, err = regexp.Compile(t) if err != nil { log.Printf("error compiling filter rewrite: %s", err) continue