more flexible regex for quick mentions, reported by dirk

master
Ted Unangst 1 year ago
parent 59e07ff522
commit 91db81b44d

@ -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]
}

Loading…
Cancel
Save