mirror of
1
Fork 0

[bugfix] allow usernames of length 1 (#1823)

Closes https://github.com/superseriousbusiness/gotosocial/issues/1691.

Co-authored-by: decentral1se <cellarspoon@riseup.net>
This commit is contained in:
decentral1se 2023-05-25 11:15:10 +02:00 committed by GitHub
parent f5c004d67d
commit 45f961a9fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -47,8 +47,8 @@ const (
mentionFinder = `(?:^|\s)(@` + usernameGrp + `+(?:@` + domainGrp + `+)?)` // Extract all mentions from a text, each mention may include domain. mentionFinder = `(?:^|\s)(@` + usernameGrp + `+(?:@` + domainGrp + `+)?)` // Extract all mentions from a text, each mention may include domain.
emojiShortcode = `\w{2,30}` // Pattern for emoji shortcodes. maximumEmojiShortcodeLength = 30 emojiShortcode = `\w{2,30}` // Pattern for emoji shortcodes. maximumEmojiShortcodeLength = 30
emojiFinder = `(?:\b)?:(` + emojiShortcode + `):(?:\b)?` // Extract all emoji shortcodes from a text. emojiFinder = `(?:\b)?:(` + emojiShortcode + `):(?:\b)?` // Extract all emoji shortcodes from a text.
usernameStrict = `^[a-z0-9_]{2,64}$` // Pattern for usernames on THIS instance. maximumUsernameLength = 64 usernameStrict = `^[a-z0-9_]{1,64}$` // Pattern for usernames on THIS instance. maximumUsernameLength = 64
usernameRelaxed = `[a-z0-9_\.]{2,}` // Relaxed version of username that can match instance accounts too. usernameRelaxed = `[a-z0-9_\.]{1,}` // Relaxed version of username that can match instance accounts too.
misskeyReportNotesFinder = `(?m)(?:^Note: ((?:http|https):\/\/.*)$)` // Extract reported Note URIs from the text of a Misskey report/flag. misskeyReportNotesFinder = `(?m)(?:^Note: ((?:http|https):\/\/.*)$)` // Extract reported Note URIs from the text of a Misskey report/flag.
ulid = `[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}` // Pattern for ULID. ulid = `[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}` // Pattern for ULID.
ulidValidate = `^` + ulid + `$` // Validate one ULID. ulidValidate = `^` + ulid + `$` // Validate one ULID.

View File

@ -93,6 +93,7 @@ func (suite *ValidationTestSuite) TestValidateUsername() {
trailingSpace := "thisusername_ends_with_a_space " trailingSpace := "thisusername_ends_with_a_space "
newlines := "this_is\n_almost_ok" newlines := "this_is\n_almost_ok"
goodUsername := "this_is_a_good_username" goodUsername := "this_is_a_good_username"
singleChar := "s"
var err error var err error
err = validate.Username(empty) err = validate.Username(empty)
@ -118,6 +119,9 @@ func (suite *ValidationTestSuite) TestValidateUsername() {
err = validate.Username(goodUsername) err = validate.Username(goodUsername)
suite.NoError(err) suite.NoError(err)
err = validate.Username(singleChar)
suite.NoError(err)
} }
func (suite *ValidationTestSuite) TestValidateEmail() { func (suite *ValidationTestSuite) TestValidateEmail() {