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]>
This commit is contained in:
1 parent
41d86c1b1c
commit
df26ef9985
3 files changed
+44
-2
No files matched your search
@@ -25,7 +25,7 @@ export interface PullRequestListPreferences {
|
||||
readonly environmentId?: EnvironmentId;
|
||||
readonly projectId?: ProjectId;
|
||||
readonly host?: string;
|
||||
readonly q?: string;
|
||||
readonly q?: string | undefined;
|
||||
readonly draft?: "only" | "hide";
|
||||
readonly review?: NonNullable<PullRequestListFilters["review"]>;
|
||||
readonly checks?: NonNullable<PullRequestListFilters["checks"]>;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
createMemoryHistory,
|
||||
createRootRoute,
|
||||
createRoute,
|
||||
createRouter,
|
||||
} from "@tanstack/react-router";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { Route as PullRequestsRoute } from "../../routes/_chat.pull-requests";
|
||||
|
||||
/** Matches a URL in a router shaped like the app's: a layout without its own search rules. */
|
||||
function matchedSearch(url: string) {
|
||||
const root = createRootRoute();
|
||||
const chat = createRoute({ getParentRoute: () => root, id: "_chat" });
|
||||
const pullRequests = createRoute({
|
||||
getParentRoute: () => chat,
|
||||
path: "pull-requests",
|
||||
validateSearch: PullRequestsRoute.options.validateSearch,
|
||||
});
|
||||
const router = createRouter({
|
||||
routeTree: root.addChildren([chat.addChildren([pullRequests])]),
|
||||
history: createMemoryHistory({ initialEntries: [url] }),
|
||||
});
|
||||
// The search a component reads through `useSearch` is the matched route's, not the URL's.
|
||||
return router.matchRoutes(router.latestLocation).at(-1)?.search as
|
||||
| Record<string, unknown>
|
||||
| undefined;
|
||||
}
|
||||
|
||||
describe("pull requests route search", () => {
|
||||
it("drops a q the URL parser turned into a number", () => {
|
||||
expect(matchedSearch("/pull-requests?q=4089")?.q).toBeUndefined();
|
||||
expect(matchedSearch("/pull-requests?q=true")?.q).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps a q that is text, including quoted digits", () => {
|
||||
expect(matchedSearch("/pull-requests?q=fix")?.q).toBe("fix");
|
||||
expect(matchedSearch("/pull-requests?q=%224089%22")?.q).toBe("4089");
|
||||
});
|
||||
});
|
||||
@@ -332,7 +332,9 @@ export const Route = createFileRoute("/_chat/pull-requests")({
|
||||
...(typeof raw.selectedEnvironmentId === "string" && raw.selectedEnvironmentId
|
||||
? { selectedEnvironmentId: raw.selectedEnvironmentId as EnvironmentId }
|
||||
: {}),
|
||||
...(typeof raw.q === "string" && raw.q ? { q: raw.q.slice(0, 200) } : {}),
|
||||
// Always an own key: the router lays this result over the parent route's unvalidated
|
||||
// search, so leaving out a `q` the URL parser made a number would let the number through.
|
||||
q: typeof raw.q === "string" && raw.q ? raw.q.slice(0, 200) : undefined,
|
||||
...(raw.draft === "only" || raw.draft === "hide" ? { draft: raw.draft } : {}),
|
||||
...(raw.review === "approved" ||
|
||||
raw.review === "changes-requested" ||
|
||||
|
||||
Reference in new issue
Block a user