FIX: UserNameSuggester should not suggest usernames with a sequence of 2 or more special chars

This commit is contained in:
Arpit Jalan 2015-09-11 16:53:26 +05:30
parent 43f8b2b41a
commit d73d4d4769
3 changed files with 7 additions and 1 deletions

View File

@ -1347,7 +1347,7 @@ en:
unique: "must be unique"
blank: "must be present"
must_begin_with_alphanumeric: "must begin with a letter or number or an underscore"
must_end_with_alphanumeric: "must end with a letter or number"
must_end_with_alphanumeric: "must end with a letter or number or an underscore"
must_not_contain_two_special_chars_in_seq: "must not contain a sequence of 2 or more special chars (.-_)"
must_not_contain_confusing_suffix: "must not contain a confusing suffix like .json or .png etc."
email:

View File

@ -38,6 +38,7 @@ module UserNameSuggester
name = name.gsub(/^[^[:alnum:]]+|\W+$/, "")
.gsub(/\W+/, "_")
.gsub(/^\_+/, '')
.gsub(/[\-_\.]{2,}/, "_")
name
end

View File

@ -75,6 +75,11 @@ describe UserNameSuggester do
expect(UserNameSuggester.suggest("myname.")).to eq('myname')
end
it 'handles usernames with a sequence of 2 or more special chars' do
expect(UserNameSuggester.suggest('Darth__Vader')).to eq('Darth_Vader')
expect(UserNameSuggester.suggest('Darth_-_Vader')).to eq('Darth_Vader')
end
it 'should handle typical facebook usernames' do
expect(UserNameSuggester.suggest('roger.nelson.3344913')).to eq('roger_nelson_33')
end