Browse Source

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.
ThibG 2 weeks ago
parent
commit
49f49cf367
2 changed files with 8 additions and 2 deletions
  1. 1
    1
      app/models/account.rb
  2. 7
    1
      spec/models/account_spec.rb

+ 1
- 1
app/models/account.rb View File

@@ -49,7 +49,7 @@
49 49
 #
50 50
 
51 51
 class Account < ApplicationRecord
52
-  USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.]+[a-z0-9_]+)?/i
52
+  USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
53 53
   MENTION_RE  = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
54 54
 
55 55
   include AccountAvatar

+ 7
- 1
spec/models/account_spec.rb View File

@@ -618,9 +618,15 @@ RSpec.describe Account, type: :model do
618 618
         expect(account).not_to model_have_error_on_field(:username)
619 619
       end
620 620
 
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
622 622
         account = Fabricate.build(:account, domain: 'domain', username: 'the-doctor')
623 623
         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?
624 630
         expect(account).to model_have_error_on_field(:username)
625 631
       end
626 632