ssh-chat/chat/sanitize.go
Dmitri Shuralyov 50001bf172 Travis: Check for gofmt issues. (#241)
* 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.
2017-07-17 15:03:55 -04:00

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, "")
}