From 5ea18a811a04a11dab88162e8e3956f72e55bc1d Mon Sep 17 00:00:00 2001 From: "commitperclip[bot]" <284812584+commitperclip[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:31:45 -0800 Subject: [PATCH] fix: Match originKindPrefix as a literal prefix by escaping LIKE wildcards (#19197) > [!NOTE] > Opened by Prospector's automated issue-fix pipeline. A maintainer reviews and decides; nothing here merges on its own. ## Thinking Path - Issue #19120 reports a defect in paperclipai/paperclip. - Root cause, as the fixing agent read it: All three originKindPrefix predicates in server/src/services/issues.ts (the issue list, the issue count and blockedInboxIssueConditions) put the raw value into a LIKE pattern, so '%', '_' and '\' acted as pattern syntax instead of literal characters. The route casts req.query to string without checking it, so a repeated query parameter reaches the service as an array, and escaping has to convert t - This pull request: Match originKindPrefix as a literal prefix by escaping LIKE wildcards ## What Changed - `server/src/services/issues.ts`: Adds originKindPrefixCondition, which applies escapeLikePattern, and uses it at all three predicates so the rule is defined once. String(prefix) keeps the existing comma-joined result for repeated query parameters; without it those requests no longer return 200, and all three repeated-parameter route tests fail. ## Verification - Reproducing test(s), added in this PR: `server/src/__tests__/issues-origin-kind-prefix.test.ts` - They fail on the base commit and pass with the fix, each twice in a fresh sandbox. - The repository's compile command passes with the fix applied. - 9 existing test file(s) near the change passed. - The full test suite passes except for the 14 file(s) that already fail on the base commit. ## Risks - Written by an automated pipeline, not a person: review it as you would an outside contribution. - Risk tier of the touched paths: 2. - The scope reviewer found it also changes, beyond the report: Missing, undefined, null, empty-string, false, zero, or NaN prefixes passed at runtime - The scope reviewer found it also changes, beyond the report: Ordinary nonempty prefixes, whitespace, repeated parameters without pattern characters, and stringifiable malformed values without pattern characters ## Model Used - opus (Anthropic Claude, via Claude Code), writing and checking the change in an isolated sandbox. - opus (Anthropic Claude, via Claude Code), reviewing it independently. ## Linked Issues Fixes #19120 A search of paperclipai/paperclip's open and closed pull requests found no other pull request that names #19120. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [ ] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with 'Fixes: #' / 'Closes #' / 'Refs #' OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub '#NNN' / 'github.com/paperclipai/paperclip' URLs) - [ ] My branch name describes the change (e.g. 'docs/...', 'fix/...') and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: commitperclip[bot] <284812584+commitperclip[bot]@users.noreply.github.com> --- .../issues-origin-kind-prefix.test.ts | 74 +++++++++++++++++++ server/src/services/issues.ts | 14 ++-- 2 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 server/src/__tests__/issues-origin-kind-prefix.test.ts diff --git a/server/src/__tests__/issues-origin-kind-prefix.test.ts b/server/src/__tests__/issues-origin-kind-prefix.test.ts new file mode 100644 index 00000000000..f02b7c6a9ab --- /dev/null +++ b/server/src/__tests__/issues-origin-kind-prefix.test.ts @@ -0,0 +1,74 @@ +import request from "supertest"; +import { expect, it } from "vitest"; +import { issues } from "@paperclipai/db"; +import { issueRoutes } from "../routes/issues.js"; +import { issueService } from "../services/issues.js"; +import { + describeEmbeddedPostgres, + resetCompanyIssueFixtures, + routeApp, + seedCompanyWithBoardAccess, + useEmbeddedPostgres, +} from "./helpers/route-test-harness.js"; + +describeEmbeddedPostgres("issue origin kind prefix", () => { + const ctx = useEmbeddedPostgres("paperclip-origin-prefix-", { + resetEach: resetCompanyIssueFixtures, + }); + + for (const attention of [undefined, "blocked"] as const) { + for (const method of ["list", "count"] as const) { + it.each(["%", "_", "plugin:sample_", "plugin:sample%", "plugin:sample\\", "plugin:", ""])( + `${method} matches literal prefix %j with attention ${attention}`, + async (prefix) => { + const { companyId } = await seedCompanyWithBoardAccess(ctx.db, "Origin prefix"); + const other = await seedCompanyWithBoardAccess(ctx.db, "Other origins"); + const originKinds = [ + "%literal", "_literal", "manual", "plugin:sample_task", + "plugin:sampleXtask", "plugin:sample%task", "plugin:sample\\task", + "plugin:sample_task:child", "plugin:other", + ]; + const rows = await ctx.db.insert(issues).values(originKinds.map((originKind) => ({ + companyId, title: originKind, originKind, status: "blocked", + }))).returning(); + await ctx.db.insert(issues).values({ + companyId: other.companyId, title: "Other company", originKind: `${prefix}other`, status: "blocked", + }); + const expected = rows.filter((row) => row.originKind!.startsWith(prefix)); + const svc = issueService(ctx.db); + const filters = { originKindPrefix: prefix, attention, includeRoutineExecutions: true }; + if (method === "count") { + expect(await svc.count(companyId, filters)).toBe(expected.length); + } else { + const result = await svc.list(companyId, filters); + expect(result.map((row) => row.id).sort()).toEqual(expected.map((row) => row.id).sort()); + } + }, + ); + } + } + + async function seedRepeatedPrefixRoute() { + const { companyId, actor } = await seedCompanyWithBoardAccess(ctx.db, "Repeated origin prefix"); + const [joined] = await ctx.db.insert(issues).values(["plugin:a,plugin:b", "plugin:a", "plugin:b"].map((originKind) => ({ + companyId, title: originKind, originKind, status: "blocked", + }))).returning(); + return { companyId, app: routeApp(ctx.db, actor, issueRoutes), joinedId: joined!.id }; + } + + it.each(["", "&attention=blocked"])("list route joins repeated prefixes with commas (%s)", async (attention) => { + const { companyId, app, joinedId } = await seedRepeatedPrefixRoute(); + const res = await request(app) + .get(`/api/companies/${companyId}/issues?originKindPrefix=plugin:a&originKindPrefix=plugin:b${attention}`) + .expect(200); + expect((res.body as { id: string }[]).map((issue) => issue.id)).toEqual([joinedId]); + }); + + it("count route joins repeated prefixes with commas", async () => { + const { companyId, app } = await seedRepeatedPrefixRoute(); + const res = await request(app) + .get(`/api/companies/${companyId}/issues/count?attention=blocked&originKindPrefix=plugin:a&originKindPrefix=plugin:b`) + .expect(200); + expect(res.body).toEqual(expect.objectContaining({ count: 1 })); + }); +}); diff --git a/server/src/services/issues.ts b/server/src/services/issues.ts index 265607ea5a9..e58df5d69dd 100644 --- a/server/src/services/issues.ts +++ b/server/src/services/issues.ts @@ -2212,6 +2212,10 @@ function escapeLikePattern(value: string): string { return value.replace(/[\\%_]/g, "\\$&"); } +function originKindPrefixCondition(prefix: string) { + return like(issues.originKind, `${escapeLikePattern(String(prefix))}%`); +} + export function clampIssueListLimit(limit: number): number { return Math.min(ISSUE_LIST_MAX_LIMIT, Math.max(1, Math.floor(limit))); } @@ -6800,7 +6804,7 @@ async function blockedInboxIssueConditions( if (filters?.originKind) conditions.push(eq(issues.originKind, filters.originKind)); if (filters?.originKindPrefix) - conditions.push(like(issues.originKind, `${filters.originKindPrefix}%`)); + conditions.push(originKindPrefixCondition(filters.originKindPrefix)); if (filters?.originId) conditions.push(eq(issues.originId, filters.originId)); if (filters?.hasPlanDocument !== undefined) { conditions.push( @@ -8720,9 +8724,7 @@ export function issueService(db: Db) { if (filters?.originKind) conditions.push(eq(issues.originKind, filters.originKind)); if (filters?.originKindPrefix) - conditions.push( - like(issues.originKind, `${filters.originKindPrefix}%`), - ); + conditions.push(originKindPrefixCondition(filters.originKindPrefix)); if (filters?.originId) conditions.push(eq(issues.originId, filters.originId)); if (filters?.hasPlanDocument !== undefined) { @@ -9046,9 +9048,7 @@ export function issueService(db: Db) { if (filters?.originKind) conditions.push(eq(issues.originKind, filters.originKind)); if (filters?.originKindPrefix) - conditions.push( - like(issues.originKind, `${filters.originKindPrefix}%`), - ); + conditions.push(originKindPrefixCondition(filters.originKindPrefix)); if (filters?.originId) conditions.push(eq(issues.originId, filters.originId)); if (filters?.hasPlanDocument !== undefined) {