more flexible regex for quick mentions, reported by dirk
Ted Unangst tedu@tedunangst.com
Fri, 03 Feb 2023 22:37:19 -0500
1 files changed,
4 insertions(+),
2 deletions(-)
jump to
M
fun.go
→
fun.go
@@ -27,6 +27,7 @@ "os"
"regexp" "strings" "time" + "unicode" "golang.org/x/net/html" "humungus.tedunangst.com/r/webs/cache"@@ -457,7 +458,8 @@ }
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 @@ }
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] }