Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: escape agent library search patterns

Richie McIlroyf598d75879a7
diff --git a/apps/web/__tests__/unit/agent-api.test.ts b/apps/web/__tests__/unit/agent-api.test.ts
index ce3bebf23..11292f6a7 100644
--- a/apps/web/__tests__/unit/agent-api.test.ts
+++ b/apps/web/__tests__/unit/agent-api.test.ts
@@ -7,6 +7,7 @@ import {
agentTranscriptRevision,
decodeAgentCursor,
encodeAgentCursor,
+ escapeAgentLikePattern,
parseAgentDate,
parseAgentLimit,
parseAgentVtt,
@@ -49,6 +50,10 @@ describe("agent API normalization", () => {
expect(parseAgentDate("2026-02-30T12:00:00Z")).toBeUndefined();
});
+ it("escapes SQL LIKE metacharacters in literal searches", () => {
+ expect(escapeAgentLikePattern("100%_ready!")).toBe("100!%!_ready!!");
+ });
+
it("normalizes VTT into millisecond cues and text", () => {
const cues = parseAgentVtt(
"WEBVTT\r\n\r\n1\r\n00:00:01.250 --> 00:00:03.500 align:start\r\nHello <b>agent</b>\r\n\r\n2\r\n00:00:04,000 --> 00:00:05,125\r\nSecond line\r\n",
diff --git a/apps/web/app/api/v1/[...route]/route.ts b/apps/web/app/api/v1/[...route]/route.ts
index 21e169e43..5fe445c60 100644
--- a/apps/web/app/api/v1/[...route]/route.ts
+++ b/apps/web/app/api/v1/[...route]/route.ts
@@ -55,7 +55,6 @@ import {
gt,
inArray,
isNull,
- like,
lt,
ne,
or,
@@ -77,6 +76,7 @@ import {
agentTranscriptRevision,
decodeAgentCursor,
encodeAgentCursor,
+ escapeAgentLikePattern,
normalizeAgentMetadata,
parseAgentDate,
parseAgentLimit,
@@ -745,7 +745,9 @@ const listCaps = Effect.fn("Agent.listCaps")(function* (
? ne(Db.videos.ownerId, principal.id)
: undefined,
isNull(Db.organizations.tombstoneAt),
- search ? like(Db.videos.name, `%${search}%`) : undefined,
+ search
+ ? sql`${Db.videos.name} LIKE ${`%${escapeAgentLikePattern(search)}%`} ESCAPE '!'`
+ : undefined,
updatedAfter ? gt(Db.videos.updatedAt, updatedAfter) : undefined,
cursorFilter,
];
diff --git a/apps/web/lib/agent-api.ts b/apps/web/lib/agent-api.ts
index 39d1ae4fa..1eace33ec 100644
--- a/apps/web/lib/agent-api.ts
+++ b/apps/web/lib/agent-api.ts
@@ -39,6 +39,9 @@ export const parseAgentLimit = (value: string | undefined) => {
return Math.min(parsed, 100);
};
+export const escapeAgentLikePattern = (value: string) =>
+ value.replace(/[!%_]/g, (match) => `!${match}`);
+
const parseAgentUtcDate = (value: string) => {
const match = value.match(
/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,3}))?Z$/,