FIX: Check against reserved usernames should be case insensitive.

This commit is contained in:
Guo Xiang Tan 2016-08-31 21:49:45 +08:00
parent 282a4e1efb
commit 90a0327fd2
2 changed files with 11 additions and 1 deletions

View file

@ -147,7 +147,9 @@ class User < ActiveRecord::Base
def self.username_available?(username) def self.username_available?(username)
lower = username.downcase 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 end
def self.plugin_staff_user_custom_fields def self.plugin_staff_user_custom_fields

View file

@ -433,6 +433,14 @@ describe User do
it 'returns false when a username is taken' do it 'returns false when a username is taken' do
expect(User.username_available?(Fabricate(:user).username)).to eq(false) expect(User.username_available?(Fabricate(:user).username)).to eq(false)
end 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 end
describe 'email_validator' do describe 'email_validator' do