Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit a4817f3

Browse files
authored
Allow + in MIDs as per MSC4009 (#3313)
This PR adds `+` to the username regex, per MSC4009. ### Pull Request Checklist <!-- Please read https://matrix-org.github.io/dendrite/development/contributing before submitting your pull request --> * [x] I have added Go unit tests or [Complement integration tests](https://github.com/matrix-org/complement) for this PR _or_ I have justified why this PR doesn't need tests * [x] Pull request includes a [sign off below using a legally identifiable name](https://matrix-org.github.io/dendrite/development/contributing#sign-off) _or_ I have already signed off privately Signed-off-by: `Matt Strapp <[email protected]>`
1 parent 00217a6 commit a4817f3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

internal/validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ var (
3838
ErrPasswordTooLong = fmt.Errorf("password too long: max %d characters", maxPasswordLength)
3939
ErrPasswordWeak = fmt.Errorf("password too weak: min %d characters", minPasswordLength)
4040
ErrUsernameTooLong = fmt.Errorf("username exceeds the maximum length of %d characters", maxUsernameLength)
41-
ErrUsernameInvalid = errors.New("username can only contain characters a-z, 0-9, or '_-./='")
41+
ErrUsernameInvalid = errors.New("username can only contain characters a-z, 0-9, or '_+-./='")
4242
ErrUsernameUnderscore = errors.New("username cannot start with a '_'")
43-
validUsernameRegex = regexp.MustCompile(`^[0-9a-z_\-=./]+$`)
43+
validUsernameRegex = regexp.MustCompile(`^[0-9a-z_\-+=./]+$`)
4444
)
4545

4646
// ValidatePassword returns an error if the password is invalid

internal/validate_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ func Test_validateUsername(t *testing.T) {
129129
localpart: "i_am_allowed=1",
130130
domain: "localhost",
131131
},
132+
{
133+
name: "special characters are allowed 3",
134+
localpart: "+55555555555",
135+
domain: "localhost",
136+
},
132137
{
133138
name: "not all special characters are allowed",
134139
localpart: "notallowed#", // contains #
@@ -139,6 +144,16 @@ func Test_validateUsername(t *testing.T) {
139144
JSON: spec.InvalidUsername(ErrUsernameInvalid.Error()),
140145
},
141146
},
147+
{
148+
name: "not all special characters are allowed 2",
149+
localpart: "<notallowed", // contains <
150+
domain: "localhost",
151+
wantErr: ErrUsernameInvalid,
152+
wantJSON: &util.JSONResponse{
153+
Code: http.StatusBadRequest,
154+
JSON: spec.InvalidUsername(ErrUsernameInvalid.Error()),
155+
},
156+
},
142157
{
143158
name: "username containing numbers",
144159
localpart: "hello1337",

0 commit comments

Comments
 (0)