Skip to content

Commit dd311c4

Browse files
committed
test(xref): add tests for array query param normalization
Express parses repeated ?q= query parameters as arrays at runtime, which would crash searchTerms() since arrays lack toLowerCase(). Add tests verifying array params are normalized to the first element.
1 parent 06120d7 commit dd311c4

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tests/routes/xref/terms.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,18 @@ describe("xref/terms - server autocomplete", () => {
152152
route(mockReq({ q: "ForeignObj" }), res);
153153
expect(res._body).toContain("foreignObject");
154154
});
155+
156+
it("normalizes array query params to first element", () => {
157+
const res = mockRes();
158+
route(mockReq({ q: ["event", "ignored"] }), res);
159+
expect(res._status).toBe(200);
160+
expect(Array.isArray(res._body)).toBeTrue();
161+
expect(res._body.length).toBeGreaterThan(0);
162+
});
163+
164+
it("returns 400 when array query param has short first element", () => {
165+
const res = mockRes();
166+
route(mockReq({ q: ["a", "event"] }), res);
167+
expect(res._status).toBe(400);
168+
});
155169
});

0 commit comments

Comments
 (0)