[bugfix] Use case-insensitive selects when getting remote accounts by username/domain (#1191)

* [bugfix] Case-insensitive account selection

* don't lowercase cache key
This commit is contained in:
tobi 2022-12-01 16:06:09 +01:00 committed by GitHub
commit cf20397f26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View file

@ -22,6 +22,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"
"codeberg.org/gruf/go-cache/v3/result"
@ -108,11 +109,13 @@ func (a *accountDB) GetAccountByUsernameDomain(ctx context.Context, username str
q := a.newAccountQ(account)
if domain != "" {
q = q.Where("? = ?", bun.Ident("account.username"), username)
q = q.Where("? = ?", bun.Ident("account.domain"), domain)
q = q.
Where("LOWER(?) = ?", bun.Ident("account.username"), strings.ToLower(username)).
Where("? = ?", bun.Ident("account.domain"), domain)
} else {
q = q.Where("? = ?", bun.Ident("account.username"), username)
q = q.Where("? IS NULL", bun.Ident("account.domain"))
q = q.
Where("? = ?", bun.Ident("account.username"), strings.ToLower(username)). // usernames on our instance are always lowercase
Where("? IS NULL", bun.Ident("account.domain"))
}
return q.Scan(ctx)