diff --git a/apps/web/src/components/pullRequest/pullRequestsRouteSearch.test.ts b/apps/web/src/components/pullRequest/pullRequestsRouteSearch.test.ts index 716a047655f2b..8906fa466f220 100644 --- a/apps/web/src/components/pullRequest/pullRequestsRouteSearch.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestsRouteSearch.test.ts @@ -41,4 +41,14 @@ describe("pull requests route search", () => { expect(matchedSearch("/pull-requests?author=4089")?.author).toBeUndefined(); expect(matchedSearch("/pull-requests?labels=4089")?.labels).toBeUndefined(); }); + + it("cuts a long author and label before an emoji the limit would split", () => { + const author = "a".repeat(199); + const label = "b".repeat(199); + expect( + matchedSearch( + `/pull-requests?${new URLSearchParams({ author: `${author}😀`, labels: `${label}🐛` })}`, + ), + ).toMatchObject({ author, labels: [label] }); + }); }); diff --git a/apps/web/src/routes/_chat.pull-requests.tsx b/apps/web/src/routes/_chat.pull-requests.tsx index 2eabb50b6c05b..da9d218949785 100644 --- a/apps/web/src/routes/_chat.pull-requests.tsx +++ b/apps/web/src/routes/_chat.pull-requests.tsx @@ -9,6 +9,10 @@ import { PullRequestsPage } from "../components/pullRequest/PullRequestsPage"; const MAX_SEARCH_LABEL_CANDIDATES = 100; +function sliceSearchText(value: string) { + return value.slice(0, splitsSurrogatePair(value, 200) ? 199 : 200); +} + function pullRequestSearchLabels(raw: unknown): PullRequestsSearch["labels"] { const values = (Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : []).slice( 0, @@ -18,7 +22,7 @@ function pullRequestSearchLabels(raw: unknown): PullRequestsSearch["labels"] { const seen = new Set(); for (const rawValue of values) { if (typeof rawValue !== "string") continue; - const value = rawValue.trim().slice(0, 200); + const value = sliceSearchText(rawValue.trim()); const key = value.toLowerCase(); if (value.length === 0 || seen.has(key)) continue; labels.push(value); @@ -61,10 +65,7 @@ export const Route = createFileRoute("/_chat/pull-requests")({ ? { selectedEnvironmentId: raw.selectedEnvironmentId as EnvironmentId } : {}), // Always include free-text keys to override numeric values in the parent route's unvalidated search. - q: - typeof raw.q === "string" && raw.q - ? raw.q.slice(0, splitsSurrogatePair(raw.q, 200) ? 199 : 200) - : undefined, + q: typeof raw.q === "string" && raw.q ? sliceSearchText(raw.q) : undefined, ...(raw.draft === "only" || raw.draft === "hide" ? { draft: raw.draft } : {}), ...(raw.review === "approved" || raw.review === "changes-requested" || @@ -74,9 +75,7 @@ export const Route = createFileRoute("/_chat/pull-requests")({ : {}), ...(raw.checks === "passing" || raw.checks === "failing" ? { checks: raw.checks } : {}), author: - typeof raw.author === "string" && raw.author.trim() - ? raw.author.trim().slice(0, 200) - : undefined, + typeof raw.author === "string" ? sliceSearchText(raw.author.trim()) || undefined : undefined, labels: pullRequestSearchLabels(raw.labels), }), component: PullRequestsPage,