FIX: fallback to `anonymous` not `user` when suggesting usernames for anonymous users (#15354)
This commit is contained in:
parent
852dc85504
commit
952bebc5a1
|
@ -42,7 +42,7 @@ class AnonymousShadowCreator
|
|||
private
|
||||
|
||||
def create_shadow!
|
||||
username = UserNameSuggester.suggest(I18n.t(:anonymous).downcase)
|
||||
username = resolve_username
|
||||
|
||||
User.transaction do
|
||||
shadow = User.create!(
|
||||
|
@ -76,4 +76,11 @@ class AnonymousShadowCreator
|
|||
shadow
|
||||
end
|
||||
end
|
||||
|
||||
def resolve_username
|
||||
username = I18n.t("anonymous").downcase
|
||||
username = "anonymous" unless UserNameSuggester.sanitize_username(username).present?
|
||||
|
||||
UserNameSuggester.suggest(username)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -78,6 +78,16 @@ describe AnonymousShadowCreator do
|
|||
|
||||
expect { AnonymousShadowCreator.get(user) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
it "falls back to username 'anonymous' if the translation for 'anonymous' consists entirely of disallowed characters" do
|
||||
# use russian locale but do not allow russian characters:
|
||||
I18n.locale = :ru
|
||||
SiteSetting.unicode_usernames = true
|
||||
SiteSetting.allowed_unicode_username_characters = "[äöü]"
|
||||
|
||||
shadow = AnonymousShadowCreator.get(user)
|
||||
|
||||
expect(shadow.username).to eq("anonymous")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue