Skip to content

Commit 89f044b

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Allow hyphens in the middle of remote user names (mastodon#9345)
Fixes mastodon#9309 This only allows hyphens in the middle of a username, much like dots, although I don't have a compelling reason to do so other than keeping the changes minimal.
1 parent 9b8fd38 commit 89f044b

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

app/models/account.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#
4848

4949
class Account < ApplicationRecord
50-
USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.]+[a-z0-9_]+)?/i
50+
USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
5151
MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
5252

5353
include AccountAvatar

spec/models/account_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,15 @@
618618
expect(account).not_to model_have_error_on_field(:username)
619619
end
620620

621-
it 'is invalid if the username doesn\'t only contains letters, numbers and underscores' do
621+
it 'is valid even if the username contains hyphens' do
622622
account = Fabricate.build(:account, domain: 'domain', username: 'the-doctor')
623623
account.valid?
624+
expect(account).to_not model_have_error_on_field(:username)
625+
end
626+
627+
it 'is invalid if the username doesn\'t only contains letters, numbers, underscores and hyphens' do
628+
account = Fabricate.build(:account, domain: 'domain', username: 'the doctor')
629+
account.valid?
624630
expect(account).to model_have_error_on_field(:username)
625631
end
626632

0 commit comments

Comments
 (0)