From 91db81b44d8e3248466f8a3d08798342c221f139 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Fri, 3 Feb 2023 22:37:19 -0500 Subject: [PATCH] more flexible regex for quick mentions, reported by dirk --- fun.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fun.go b/fun.go index 4f89d6a..c8afcfa 100644 --- a/fun.go +++ b/fun.go @@ -27,6 +27,7 @@ import ( "regexp" "strings" "time" + "unicode" "golang.org/x/net/html" "humungus.tedunangst.com/r/webs/cache" @@ -457,7 +458,8 @@ func memetize(honk *Honk) { honk.Noise = re_memes.ReplaceAllStringFunc(honk.Noise, repl) } -var re_quickmention = regexp.MustCompile("(^|[ \n])@[[:alnum:]]+([ \n.]|$)") +// be mindful not to match trailing @ +var re_quickmention = regexp.MustCompile("(^|[ \n])@[[:alnum:]]+([ \n.,']|$)") func quickrename(s string, userid int64) string { nonstop := true @@ -472,7 +474,7 @@ func quickrename(s string, userid int64) string { prefix += "@" m = m[1:] tail := "" - if last := m[len(m)-1]; last == ' ' || last == '\n' || last == '.' { + if last := m[len(m)-1]; last == ' ' || last == '\n' || unicode.IsPunct(rune(last)) { tail = m[len(m)-1:] m = m[:len(m)-1] }