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
Original file line number Diff line number Diff line change
Expand Up @@ -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] });
});
});
15 changes: 7 additions & 8 deletions apps/web/src/routes/_chat.pull-requests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,7 +22,7 @@ function pullRequestSearchLabels(raw: unknown): PullRequestsSearch["labels"] {
const seen = new Set<string>();
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);
Expand Down Expand Up @@ -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" ||
Expand All @@ -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,
Expand Down
Loading