From 5ce7f13bba1ac230b3fab56f5196a1dc5cebd3ec Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Tue, 22 Mar 2022 12:14:09 +0100 Subject: [PATCH] Fix #2287 by trying to fetch account by lowercase localpart and as passed by request --- userapi/storage/shared/storage.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/userapi/storage/shared/storage.go b/userapi/storage/shared/storage.go index febf03221..f4d916c6e 100644 --- a/userapi/storage/shared/storage.go +++ b/userapi/storage/shared/storage.go @@ -23,6 +23,7 @@ import ( "errors" "fmt" "strconv" + "strings" "time" "github.com/matrix-org/gomatrixserverlib" @@ -298,7 +299,20 @@ func (d *Database) CheckAccountAvailability(ctx context.Context, localpart strin // Returns sql.ErrNoRows if no account exists which matches the given localpart. func (d *Database) GetAccountByLocalpart(ctx context.Context, localpart string, ) (*api.Account, error) { - return d.Accounts.SelectAccountByLocalpart(ctx, localpart) + // try to get the account with lowercase localpart (majority) + acc, err := d.Accounts.SelectAccountByLocalpart(ctx, strings.ToLower(localpart)) + switch err { + case sql.ErrNoRows: // try with localpart as passed by the request + acc, err = d.Accounts.SelectAccountByLocalpart(ctx, localpart) + if err != nil { + return nil, err + } + return acc, nil + case nil: + return acc, nil + default: + return nil, err + } } // SearchProfiles returns all profiles where the provided localpart or display name