Allow hyphens in the middle of remote user names (#9345)
Fixes #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.lolsob-rspec
parent
2490dcffe4
commit
80ef517747
|
@ -46,7 +46,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class Account < ApplicationRecord
|
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
|
MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
|
||||||
|
|
||||||
include AccountAvatar
|
include AccountAvatar
|
||||||
|
|
|
@ -618,9 +618,15 @@ RSpec.describe Account, type: :model do
|
||||||
expect(account).not_to model_have_error_on_field(:username)
|
expect(account).not_to model_have_error_on_field(:username)
|
||||||
end
|
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 = Fabricate.build(:account, domain: 'domain', username: 'the-doctor')
|
||||||
account.valid?
|
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)
|
expect(account).to model_have_error_on_field(:username)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue