FIX: fallback to `anonymous` not `user` when suggesting usernames for anonymous users (#15354)

This commit is contained in:
Andrei Prigorshnev 2021-12-21 18:09:55 +01:00 committed by GitHub
parent 852dc85504
commit 952bebc5a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -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

View File

@ -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