mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
FIX: 500 error when creating a user with an integer username (#16370)
Via the API it is possible to create a user with an integer username. So 123 instead of "123". This causes the following 500 error: ``` NoMethodError (undefined method `unicode_normalize' for 1:Integer) app/models/user.rb:276:in `normalize_username' ``` See: https://meta.discourse.org/t/222281
This commit is contained in:
parent
1da4b9eeb3
commit
ec2930712d
@ -273,7 +273,7 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.normalize_username(username)
|
||||
username.unicode_normalize.downcase if username.present?
|
||||
username.to_s.unicode_normalize.downcase if username.present?
|
||||
end
|
||||
|
||||
def self.username_available?(username, email = nil, allow_reserved_username: false)
|
||||
|
@ -50,6 +50,12 @@ describe User do
|
||||
expect(user.errors.full_messages.first)
|
||||
.to include(user_error_message(:username, :same_as_password))
|
||||
end
|
||||
|
||||
describe 'when a username is an integer' do
|
||||
it 'is converted to a string on normalization' do
|
||||
expect(User.normalize_username(123)).to eq("123") # This is possible via the API
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'name' do
|
||||
|
Loading…
Reference in New Issue
Block a user