Safer ident transform
This commit is contained in:
parent
495a6303dc
commit
6d33fa5d93
1 changed files with 11 additions and 4 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue