mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-13 07:37:17 +03:00
Limit username length to 16 chars (#167)
This commit is contained in:
parent
c4604fde94
commit
a55b78ccdb
@ -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:]]")
|
||||
|
Loading…
x
Reference in New Issue
Block a user