mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Don't escape + in user ID localparts
This commit is contained in:
parent
ac5c2c2210
commit
57d46e6a23
2 changed files with 5 additions and 5 deletions
|
|
@ -72,7 +72,7 @@ func (userID UserID) URI() *MatrixURI {
|
|||
}
|
||||
}
|
||||
|
||||
var ValidLocalpartRegex = regexp.MustCompile("^[0-9a-z-.=_/]+$")
|
||||
var ValidLocalpartRegex = regexp.MustCompile("^[0-9a-z-.=_/+]+$")
|
||||
|
||||
// ValidateUserLocalpart validates a Matrix user ID localpart using the grammar
|
||||
// in https://matrix.org/docs/spec/appendices#user-identifier
|
||||
|
|
@ -132,7 +132,7 @@ func escape(buf *bytes.Buffer, b byte) {
|
|||
}
|
||||
|
||||
func shouldEncode(b byte) bool {
|
||||
return b != '-' && b != '.' && b != '_' && !(b >= '0' && b <= '9') && !(b >= 'a' && b <= 'z') && !(b >= 'A' && b <= 'Z')
|
||||
return b != '-' && b != '.' && b != '_' && b != '+' && !(b >= '0' && b <= '9') && !(b >= 'a' && b <= 'z') && !(b >= 'A' && b <= 'Z')
|
||||
}
|
||||
|
||||
func shouldEscape(b byte) bool {
|
||||
|
|
@ -140,7 +140,7 @@ func shouldEscape(b byte) bool {
|
|||
}
|
||||
|
||||
func isValidByte(b byte) bool {
|
||||
return isValidEscapedChar(b) || (b >= '0' && b <= '9') || b == '.' || b == '=' || b == '-'
|
||||
return isValidEscapedChar(b) || (b >= '0' && b <= '9') || b == '.' || b == '=' || b == '-' || b == '+'
|
||||
}
|
||||
|
||||
func isValidEscapedChar(b byte) bool {
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ func TestUserID_ParseAndValidate_NotLong(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUserIDEncoding(t *testing.T) {
|
||||
const inputLocalpart = "This localpart contains IlLeGaL chäracters 🚨"
|
||||
const encodedLocalpart = "_this=20localpart=20contains=20_il_le_ga_l=20ch=c3=a4racters=20=f0=9f=9a=a8"
|
||||
const inputLocalpart = "This local+part contains IlLeGaL chäracters 🚨"
|
||||
const encodedLocalpart = "_this=20local+part=20contains=20_il_le_ga_l=20ch=c3=a4racters=20=f0=9f=9a=a8"
|
||||
const inputServerName = "example.com"
|
||||
userID := id.NewEncodedUserID(inputLocalpart, inputServerName)
|
||||
parsedLocalpart, parsedServerName, err := userID.ParseAndValidate()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue