FIX: Don't error out on empty reserved_usernames setting (#29305)

We're seeing errors in logs due to some sites setting the reserved_usernames setting to nil. This is causing multiple use cases upstream of User#reserved_username? to error out.

This commit changes from using the raw #reserved_usernames to using the #reserved_usernames_map helper which exists on list-type site settings. It returns an empty array if the raw value is nil or empty string.
This commit is contained in:
Ted Johansson
2024-10-21 14:38:37 +08:00
committed by GitHub
parent 6f55457652
commit 56df077931
5 changed files with 19 additions and 11 deletions

View File

@ -1076,6 +1076,12 @@ RSpec.describe User do
expect(User.reserved_username?("löwe")).to eq(true) # NFC
expect(User.reserved_username?("käfer")).to eq(true) # NFC
end
it "does not error out when there are no reserved usernames" do
SiteSetting.stubs(:reserved_usernames).returns(nil)
expect { User.username_available?("Foo") }.not_to raise_error
end
end
describe "email_validator" do