FIX: don't raise an error on integer usernames

This commit is contained in:
Rishabh Nambiar 2018-09-10 21:50:51 +05:30
parent 2b7e50cab8
commit 81c87df18a
2 changed files with 5 additions and 1 deletions

View File

@ -39,7 +39,7 @@ module UserNameSuggester
end
def self.sanitize_username(name)
name = ActiveSupport::Inflector.transliterate(name)
name = ActiveSupport::Inflector.transliterate(name.to_s)
# 1. replace characters that aren't allowed with '_'
name.gsub!(UsernameValidator::CONFUSING_EXTENSIONS, "_")
name.gsub!(/[^\w.-]/, "_")

View File

@ -18,6 +18,10 @@ describe UserNameSuggester do
expect(UserNameSuggester.suggest(nil)).to eq(nil)
end
it "doesn't raise an error on integer username" do
expect(UserNameSuggester.suggest(999)).to eq('999')
end
it 'corrects weird characters' do
expect(UserNameSuggester.suggest("Darth%^Vader")).to eq('Darth_Vader')
end