From 340ed7b258444d5a180b4684cdc805bb7960e1de Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Sun, 24 Nov 2024 17:42:30 +0100 Subject: [PATCH] fix(federation): :bug: Correctly handle non-lowercase acct queries in account lookups --- api/api/v1/accounts/lookup/index.test.ts | 24 ++++++++++++++++++++++++ api/api/v1/accounts/lookup/index.ts | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/api/api/v1/accounts/lookup/index.test.ts b/api/api/v1/accounts/lookup/index.test.ts index b880b8c3..021c8b50 100644 --- a/api/api/v1/accounts/lookup/index.test.ts +++ b/api/api/v1/accounts/lookup/index.test.ts @@ -34,4 +34,28 @@ describe(meta.route, () => { }), ); }); + + test("should automatically lowercase the acct", async () => { + const response = await fakeRequest( + `${meta.route}?acct=${users[0].data.username.toUpperCase()}`, + { + headers: { + Authorization: `Bearer ${tokens[0].data.accessToken}`, + }, + }, + ); + + expect(response.status).toBe(200); + + const data = (await response.json()) as ApiAccount[]; + expect(data).toEqual( + expect.objectContaining({ + id: users[0].id, + username: users[0].data.username, + display_name: users[0].data.displayName, + avatar: expect.any(String), + header: expect.any(String), + }), + ); + }); }); diff --git a/api/api/v1/accounts/lookup/index.ts b/api/api/v1/accounts/lookup/index.ts index f09a9ada..fdbf36ac 100644 --- a/api/api/v1/accounts/lookup/index.ts +++ b/api/api/v1/accounts/lookup/index.ts @@ -23,7 +23,7 @@ export const meta = applyConfig({ export const schemas = { query: z.object({ - acct: z.string().min(1).max(512), + acct: z.string().min(1).max(512).toLowerCase(), }), };