Merge pull request #6383 from discourse/fix_username_suggester

FIX: don't raise an error on integer usernames in user_name_suggester
This commit is contained in:
Rishabh 2018-09-11 00:30:29 +05:30 committed by GitHub
commit 80eace4268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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