mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-13 15:47:17 +03:00
* Travis: Check for gofmt issues. This will help catch issues like https://github.com/shazow/ssh-chat/pull/240#discussion_r127626103 in CI. * chat: Fix gofmt issue.
26 lines
610 B
Go
26 lines
610 B
Go
package chat
|
|
|
|
import "regexp"
|
|
|
|
var reStripName = regexp.MustCompile("[^\\w.-]")
|
|
|
|
const maxLength = 16
|
|
|
|
// SanitizeName returns a name with only allowed characters and a reasonable length
|
|
func SanitizeName(s string) string {
|
|
s = reStripName.ReplaceAllString(s, "")
|
|
nameLength := maxLength
|
|
if len(s) <= maxLength {
|
|
nameLength = len(s)
|
|
}
|
|
s = s[:nameLength]
|
|
return s
|
|
}
|
|
|
|
var reStripData = regexp.MustCompile("[^[:ascii:]]")
|
|
|
|
// SanitizeData returns a string with only allowed characters for client-provided metadata inputs.
|
|
func SanitizeData(s string) string {
|
|
return reStripData.ReplaceAllString(s, "")
|
|
}
|