FIX: Respect unicode whitelist when suggesting username
This commit is contained in:
parent
5cf299733a
commit
9e4fb262cf
|
@ -115,7 +115,7 @@ module UserNameSuggester
|
|||
end
|
||||
|
||||
name.gsub!(UsernameValidator.invalid_char_pattern, '_')
|
||||
name.chars.map! { |c| UsernameValidator.whitelisted_char?(c) ? c : '_' } if UsernameValidator.char_whitelist_exists?
|
||||
name = apply_whitelist(name) if UsernameValidator.char_whitelist_exists?
|
||||
name.gsub!(UsernameValidator::INVALID_LEADING_CHAR_PATTERN, '')
|
||||
name.gsub!(UsernameValidator::CONFUSING_EXTENSIONS, "_")
|
||||
name.gsub!(UsernameValidator::INVALID_TRAILING_CHAR_PATTERN, '')
|
||||
|
@ -123,6 +123,12 @@ module UserNameSuggester
|
|||
name
|
||||
end
|
||||
|
||||
def self.apply_whitelist(name)
|
||||
name.grapheme_clusters
|
||||
.map { |c| UsernameValidator.whitelisted_char?(c) ? c : '_' }
|
||||
.join
|
||||
end
|
||||
|
||||
def self.rightsize_username(name)
|
||||
name = truncate(name, User.username_length.end)
|
||||
name.gsub!(UsernameValidator::INVALID_TRAILING_CHAR_PATTERN, '')
|
||||
|
|
|
@ -170,6 +170,17 @@ describe UserNameSuggester do
|
|||
expect(UserNameSuggester.suggest('য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া'))
|
||||
.to eq('য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া-য়া')
|
||||
end
|
||||
|
||||
it "uses whitelist" do
|
||||
SiteSetting.unicode_username_character_whitelist = "[äöüßÄÖÜẞ]"
|
||||
|
||||
expect(UserNameSuggester.suggest('πουλί')).to eq('111')
|
||||
expect(UserNameSuggester.suggest('a鳥b')).to eq('a_b')
|
||||
expect(UserNameSuggester.suggest('Löwe')).to eq('Löwe')
|
||||
|
||||
SiteSetting.unicode_username_character_whitelist = "[য়া]"
|
||||
expect(UserNameSuggester.suggest('aয়াb鳥c')).to eq('aয়াb_c')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue