mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: UserNameSuggester should not suggest usernames with a sequence of 2 or more special chars
This commit is contained in:
parent
43f8b2b41a
commit
d73d4d4769
3 changed files with 7 additions and 1 deletions
|
@ -1347,7 +1347,7 @@ en:
|
||||||
unique: "must be unique"
|
unique: "must be unique"
|
||||||
blank: "must be present"
|
blank: "must be present"
|
||||||
must_begin_with_alphanumeric: "must begin with a letter or number or an underscore"
|
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_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."
|
must_not_contain_confusing_suffix: "must not contain a confusing suffix like .json or .png etc."
|
||||||
email:
|
email:
|
||||||
|
|
|
@ -38,6 +38,7 @@ module UserNameSuggester
|
||||||
name = name.gsub(/^[^[:alnum:]]+|\W+$/, "")
|
name = name.gsub(/^[^[:alnum:]]+|\W+$/, "")
|
||||||
.gsub(/\W+/, "_")
|
.gsub(/\W+/, "_")
|
||||||
.gsub(/^\_+/, '')
|
.gsub(/^\_+/, '')
|
||||||
|
.gsub(/[\-_\.]{2,}/, "_")
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,11 @@ describe UserNameSuggester do
|
||||||
expect(UserNameSuggester.suggest("myname.")).to eq('myname')
|
expect(UserNameSuggester.suggest("myname.")).to eq('myname')
|
||||||
end
|
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
|
it 'should handle typical facebook usernames' do
|
||||||
expect(UserNameSuggester.suggest('roger.nelson.3344913')).to eq('roger_nelson_33')
|
expect(UserNameSuggester.suggest('roger.nelson.3344913')).to eq('roger_nelson_33')
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue