mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-13 15:47:17 +03:00
18 lines
462 B
Go
18 lines
462 B
Go
package chat
|
|
|
|
import "regexp"
|
|
|
|
var reStripName = regexp.MustCompile("[^\\w.-]")
|
|
|
|
// SanitizeName returns a name with only allowed characters.
|
|
func SanitizeName(s string) string {
|
|
return reStripName.ReplaceAllString(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, "")
|
|
}
|