diff --git a/chat/sanitize.go b/chat/sanitize.go index 8b162cd..b567825 100644 --- a/chat/sanitize.go +++ b/chat/sanitize.go @@ -3,10 +3,17 @@ package chat import "regexp" var reStripName = regexp.MustCompile("[^\\w.-]") +const maxLength = 16 -// SanitizeName returns a name with only allowed characters. +// SanitizeName returns a name with only allowed characters and a reasonable length func SanitizeName(s string) string { - return reStripName.ReplaceAllString(s, "") + s = reStripName.ReplaceAllString(s, "") + nameLength := maxLength + if len(s) <= maxLength { + nameLength = len(s) + } + s = s[:nameLength] + return s } var reStripData = regexp.MustCompile("[^[:ascii:]]")