diff --git a/svc/util/queries.ts b/svc/util/queries.ts index c337df06a..d6bf8407f 100644 --- a/svc/util/queries.ts +++ b/svc/util/queries.ts @@ -441,7 +441,7 @@ export async function isRecentlyVisited(accountId: number): Promise { export async function search(query: string) { let accountIdMatch: any[] = []; - if (Number.isInteger(Number(query))) { + if (Number.isInteger(Number(query)) && /^\d+$/.test(query)) { let query32 = isSteamID64(query) ? convert64to32(query) : query; accountIdMatch = await db .select(["account_id", "personaname", "avatarfull"]) diff --git a/test/test.ts b/test/test.ts index 7fe31494c..b215a6942 100644 --- a/test/test.ts +++ b/test/test.ts @@ -526,6 +526,31 @@ suite(c.blue("API ROUTES"), async () => { ); } }); + for (const query of ["1e3", "1.0", "5."]) { + test(`search should not throw for ${query}`, async () => { + const res = await supertest(app).get("/api/search").query({ q: query }); + assert.equal(res.statusCode, 200); + assert.ok(Array.isArray(res.body)); + }); + } + test("search for a player with an exponential-looking name", async () => { + const accountId = 120269134; + const player = await db("players") + .where({ account_id: accountId }) + .first("personaname"); + try { + await db("players") + .where({ account_id: accountId }) + .update({ personaname: "1e3" }); + const res = await supertest(app).get("/api/search").query({ q: "1e3" }); + assert.equal(res.statusCode, 200); + assert.ok(res.body.some((p: User) => p.account_id === accountId)); + } finally { + await db("players") + .where({ account_id: accountId }) + .update({ personaname: player.personaname }); + } + }); test("search for steamid32", async () => { const res = await supertest(app).get(`/api/search?q=120269134`); assert.equal(res.statusCode, 200);