Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion svc/util/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ export async function isRecentlyVisited(accountId: number): Promise<boolean> {

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"])
Expand Down
25 changes: 25 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down