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