Safer ident transform

This commit is contained in:
Alex 2020-02-26 15:59:33 +01:00
parent 495a6303dc
commit 6d33fa5d93

View file

@ -2,7 +2,7 @@ package appservice
import (
"fmt"
"strings"
"unicode"
log "github.com/sirupsen/logrus"
@ -44,8 +44,15 @@ func userMxId(protocol string, id UserID) string {
}
func safeStringForId(in string) string {
id2 := strings.ReplaceAll(in, "#", "")
id2 = strings.ReplaceAll(id2, "@", "__")
id2 = strings.ReplaceAll(id2, ":", "_")
id2 := ""
for _, c := range in {
if c == '@' {
id2 += "__"
} else if c == ':' {
id2 += "_"
} else if unicode.IsDigit(c) || unicode.IsLetter(c) {
id2 += string(c)
}
}
return id2
}