Limit username length to 16 chars (#167)

This commit is contained in:
A. Campbell 2016-08-03 12:59:02 -04:00 committed by Andrey Petrov
parent c4604fde94
commit a55b78ccdb

View File

@ -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:]]")