fix(auth): do not allow commas in usernames

This commit is contained in:
kolaente
2024-12-16 23:09:35 +01:00
parent 3f97414497
commit 4359819faf

View File

@@ -18,18 +18,24 @@ package user
import (
"github.com/asaskevich/govalidator"
"strings"
)
func init() {
govalidator.TagMap["username"] = func(i string) bool {
// To avoid making this overly complicated, we only two things:
// To avoid making this overly complicated, we only check three things:
// 1. No Spaces
// 2. Should not look like an url
// 3. Should not contain , (because then it will be impossible to search for)
if govalidator.HasWhitespace(i) {
return false
}
if govalidator.IsURL(i) {
return false
}
if govalidator.HasWhitespace(i) {
if strings.Contains(i, ",") {
return false
}