aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-26 15:59:33 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-26 15:59:33 +0100
commit6d33fa5d937be3e33fa9cf14d35fc9ab45712750 (patch)
treee5ed34c15f897f65e19e3cc8b77e756434e4409e
parent495a6303dcf4036fa1222b7ddfdbb9f37be68e7e (diff)
downloadeasybridge-6d33fa5d937be3e33fa9cf14d35fc9ab45712750.tar.gz
easybridge-6d33fa5d937be3e33fa9cf14d35fc9ab45712750.zip
Safer ident transform
-rw-r--r--appservice/util.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/appservice/util.go b/appservice/util.go
index 4175fb0..160f492 100644
--- a/appservice/util.go
+++ b/appservice/util.go
@@ -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
}