mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 20:15:47 +08:00
FIX: Check against reserved usernames should be case insensitive.
This commit is contained in:
parent
282a4e1efb
commit
90a0327fd2
|
@ -147,7 +147,9 @@ class User < ActiveRecord::Base
|
|||
|
||||
def self.username_available?(username)
|
||||
lower = username.downcase
|
||||
User.where(username_lower: lower).blank? && !SiteSetting.reserved_usernames.split("|").include?(username)
|
||||
|
||||
User.where(username_lower: lower).blank? &&
|
||||
!SiteSetting.reserved_usernames.split("|").any? { |reserved| reserved.casecmp(username) == 0 }
|
||||
end
|
||||
|
||||
def self.plugin_staff_user_custom_fields
|
||||
|
|
|
@ -433,6 +433,14 @@ describe User do
|
|||
it 'returns false when a username is taken' do
|
||||
expect(User.username_available?(Fabricate(:user).username)).to eq(false)
|
||||
end
|
||||
|
||||
it 'returns false when a username is reserved' do
|
||||
SiteSetting.reserved_usernames = 'test|donkey'
|
||||
|
||||
expect(User.username_available?('donkey')).to eq(false)
|
||||
expect(User.username_available?('DonKey')).to eq(false)
|
||||
expect(User.username_available?('test')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'email_validator' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user