Skip to content

Commit

Permalink
allow + in usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
wunter8 committed Apr 4, 2024
1 parent 130039f commit e4d22eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion user/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const (
)

var (
allowedUsernameRegex = regexp.MustCompile(`^[-_.@a-zA-Z0-9]+$`) // Does not include Everyone (*)
allowedUsernameRegex = regexp.MustCompile(`^[-_.+@a-zA-Z0-9]+$`) // Does not include Everyone (*)
allowedTopicRegex = regexp.MustCompile(`^[-_A-Za-z0-9]{1,64}$`) // No '*'
allowedTopicPatternRegex = regexp.MustCompile(`^[-_*A-Za-z0-9]{1,64}$`) // Adds '*' for wildcards!
allowedTierRegex = regexp.MustCompile(`^[-_A-Za-z0-9]{1,64}$`)
Expand Down
12 changes: 12 additions & 0 deletions user/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,15 @@ func TestTierContext(t *testing.T) {
require.Equal(t, "price_456", context["stripe_yearly_price_id"])

}

func TestUsernameRegex(t *testing.T) {
username := "phil"
username_email := "phil@ntfy.sh"
username_email_alias := "phil+alias@ntfy.sh"
username_invalid := "phil\rocks"

require.True(t, AllowedUsername(username))
require.True(t, AllowedUsername(username_email))
require.True(t, AllowedUsername(username_email_alias))
require.False(t, AllowedUsername(username_invalid))
}

0 comments on commit e4d22eb

Please sign in to comment.