Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: address agent API code scanning alerts
Richie McIlroy0793d9ae6f92
diff --git a/apps/web/__tests__/e2e/agent-local-e2e.test.ts b/apps/web/__tests__/e2e/agent-local-e2e.test.tsindex f33482564..4398ca3c6 100644--- a/apps/web/__tests__/e2e/agent-local-e2e.test.ts+++ b/apps/web/__tests__/e2e/agent-local-e2e.test.ts@@ -451,8 +451,9 @@ const startApiServer = async () => {outgoing.writeHead(response.status, Object.fromEntries(response.headers));outgoing.end(responseBody);} catch (error) {+ console.error("Agent E2E request failed", error);outgoing.writeHead(500, { "Content-Type": "text/plain" });- outgoing.end(error instanceof Error ? error.message : String(error));+ outgoing.end("Internal Server Error");}});await new Promise<void>((resolveListen, reject) => {diff --git a/apps/web/__tests__/unit/agent-api.test.ts b/apps/web/__tests__/unit/agent-api.test.tsindex c0980ebd2..dfb13d91a 100644--- a/apps/web/__tests__/unit/agent-api.test.ts+++ b/apps/web/__tests__/unit/agent-api.test.ts@@ -77,6 +77,17 @@ describe("agent API normalization", () => {expect(agentTranscriptRevision(rendered)).toMatch(/^[a-f0-9]{64}$/);});+ it("removes complete and unterminated VTT tags", () => {+ const cues = parseAgentVtt(+ "WEBVTT\n\n1\n00:00:00.000 --> 00:00:01.000\nSafe <script>alert(1)</script> text\n\n2\n00:00:01.000 --> 00:00:02.000\nBefore <script\n",+ );++ expect(cues).toEqual([+ { startMs: 0, endMs: 1_000, text: "Safe alert(1) text" },+ { startMs: 1_000, endMs: 2_000, text: "Before" },+ ]);+ });+it("handles representative and large synthetic transcript shapes", () => {for (const bytes of [10_000, 100_000, 500_000]) {const vtt = makeSyntheticVtt(bytes);diff --git a/apps/web/lib/agent-api.ts b/apps/web/lib/agent-api.tsindex f9dd23a57..080d72489 100644--- a/apps/web/lib/agent-api.ts+++ b/apps/web/lib/agent-api.ts@@ -110,11 +110,27 @@ const parseVttTimestamp = (value: string) => {return ((hours * 60 + minutes) * 60 + seconds) * 1000 + milliseconds;};+const stripVttCueTags = (value: string) => {+ const text: string[] = [];+ let insideTag = false;++ for (const character of value) {+ if (character === "<") {+ insideTag = true;+ continue;+ }+ if (insideTag) {+ if (character === ">") insideTag = false;+ continue;+ }+ text.push(character);+ }++ return text.join("");+};+const normalizeCueText = (lines: string[]) =>- lines- .join("\n")- .replace(/<[^>]+>/g, "")- .trim();+ stripVttCueTags(lines.join("\n")).trim();export const parseAgentVtt = (vtt: string,