Skip to content

Commit d330519

Browse files
ClearlyClairemayaeh
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 8c7fefe commit d330519

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
@@ -46,7 +46,7 @@
4646
#
4747

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

5252
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)