Fix UniqueUsernameValidator comparison (#6926)
Comparison was downcasing only one side, therefore if previously existing account had a non-lowercase spelling, it would be ignored when checking for duplicates. New rake task `mastodon:maintenance:find_duplicate_usernames` will help find constraint violations that might have occured from the presence of this bug. Bump version to 2.3.3
This commit is contained in:
parent
40e5d2303b
commit
2a90da1837
4 changed files with 21 additions and 3 deletions
|
@ -30,7 +30,7 @@ module AccountFinderConcern
|
|||
end
|
||||
|
||||
def account
|
||||
scoped_accounts.take
|
||||
scoped_accounts.order(id: :asc).take
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -6,7 +6,7 @@ class UniqueUsernameValidator < ActiveModel::Validator
|
|||
|
||||
normalized_username = account.username.downcase.delete('.')
|
||||
|
||||
scope = Account.where(domain: nil, username: normalized_username)
|
||||
scope = Account.where(domain: nil).where('lower(username) = ?', normalized_username)
|
||||
scope = scope.where.not(id: account.id) if account.persisted?
|
||||
|
||||
account.errors.add(:username, :taken) if scope.exists?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue