Skip to content

Commit

Permalink
Allow hyphens in the middle of remote user names (mastodon#9345)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent 9b8fd38 commit 89f044b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#

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

include AccountAvatar
Expand Down
8 changes: 7 additions & 1 deletion spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,15 @@
expect(account).not_to model_have_error_on_field(:username)
end

it 'is invalid if the username doesn\'t only contains letters, numbers and underscores' do
it 'is valid even if the username contains hyphens' do
account = Fabricate.build(:account, domain: 'domain', username: 'the-doctor')
account.valid?
expect(account).to_not model_have_error_on_field(:username)
end

it 'is invalid if the username doesn\'t only contains letters, numbers, underscores and hyphens' do
account = Fabricate.build(:account, domain: 'domain', username: 'the doctor')
account.valid?
expect(account).to model_have_error_on_field(:username)
end

Expand Down

0 comments on commit 89f044b

Please sign in to comment.