Skip to content

Commit df26ef9

Browse files
ScottN-PVclaude
andauthored
fix(web): a numeric q in the pull requests URL no longer crashes the page (#18666)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 41d86c1 commit df26ef9

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎apps/web/src/components/pullRequest/pullRequestListPreferences.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface PullRequestListPreferences {
2525
readonly environmentId?: EnvironmentId;
2626
readonly projectId?: ProjectId;
2727
readonly host?: string;
28-
readonly q?: string;
28+
readonly q?: string | undefined;
2929
readonly draft?: "only" | "hide";
3030
readonly review?: NonNullable<PullRequestListFilters["review"]>;
3131
readonly checks?: NonNullable<PullRequestListFilters["checks"]>;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {
2+
createMemoryHistory,
3+
createRootRoute,
4+
createRoute,
5+
createRouter,
6+
} from "@tanstack/react-router";
7+
import { describe, expect, it } from "vite-plus/test";
8+
9+
import { Route as PullRequestsRoute } from "../../routes/_chat.pull-requests";
10+
11+
/** Matches a URL in a router shaped like the app's: a layout without its own search rules. */
12+
function matchedSearch(url: string) {
13+
const root = createRootRoute();
14+
const chat = createRoute({ getParentRoute: () => root, id: "_chat" });
15+
const pullRequests = createRoute({
16+
getParentRoute: () => chat,
17+
path: "pull-requests",
18+
validateSearch: PullRequestsRoute.options.validateSearch,
19+
});
20+
const router = createRouter({
21+
routeTree: root.addChildren([chat.addChildren([pullRequests])]),
22+
history: createMemoryHistory({ initialEntries: [url] }),
23+
});
24+
// The search a component reads through `useSearch` is the matched route's, not the URL's.
25+
return router.matchRoutes(router.latestLocation).at(-1)?.search as
26+
| Record<string, unknown>
27+
| undefined;
28+
}
29+
30+
describe("pull requests route search", () => {
31+
it("drops a q the URL parser turned into a number", () => {
32+
expect(matchedSearch("/pull-requests?q=4089")?.q).toBeUndefined();
33+
expect(matchedSearch("/pull-requests?q=true")?.q).toBeUndefined();
34+
});
35+
36+
it("keeps a q that is text, including quoted digits", () => {
37+
expect(matchedSearch("/pull-requests?q=fix")?.q).toBe("fix");
38+
expect(matchedSearch("/pull-requests?q=%224089%22")?.q).toBe("4089");
39+
});
40+
});

‎apps/web/src/routes/_chat.pull-requests.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ export const Route = createFileRoute("/_chat/pull-requests")({
332332
...(typeof raw.selectedEnvironmentId === "string" && raw.selectedEnvironmentId
333333
? { selectedEnvironmentId: raw.selectedEnvironmentId as EnvironmentId }
334334
: {}),
335-
...(typeof raw.q === "string" && raw.q ? { q: raw.q.slice(0, 200) } : {}),
335+
// Always an own key: the router lays this result over the parent route's unvalidated
336+
// search, so leaving out a `q` the URL parser made a number would let the number through.
337+
q: typeof raw.q === "string" && raw.q ? raw.q.slice(0, 200) : undefined,
336338
...(raw.draft === "only" || raw.draft === "hide" ? { draft: raw.draft } : {}),
337339
...(raw.review === "approved" ||
338340
raw.review === "changes-requested" ||

0 commit comments

Comments
 (0)