diff --git a/packages/app/src/linear-source.ts b/packages/app/src/linear-source.ts index dbe08335..0f8abb99 100644 --- a/packages/app/src/linear-source.ts +++ b/packages/app/src/linear-source.ts @@ -2,7 +2,12 @@ import Mustache from "mustache"; import type { WorkItem } from "./types"; const object = (value: unknown): Record => value !== null && typeof value === "object" && !Array.isArray(value) ? value as Record : {}; -const text = (value: unknown): string => typeof value === "string" ? value : ""; +const decodeHtmlEntities = (value: string): string => value.replace(/&(?:#(\d+)|#x([\da-f]+)|([a-z][\da-z]+));/gi, (entity, decimal, hexadecimal, named) => { + if (decimal) return String.fromCodePoint(Number(decimal)); + if (hexadecimal) return String.fromCodePoint(parseInt(hexadecimal, 16)); + return ({ amp: "&", apos: "'", gt: ">", lt: "<", quot: '"' } as Record)[named.toLowerCase()] ?? entity; +}); +const text = (value: unknown): string => typeof value === "string" ? decodeHtmlEntities(value) : ""; export const DEFAULT_CONTEXT_TEMPLATE = `--- pipe: "{{{flow.name}}}" diff --git a/packages/app/test/ticket-prompt.test.ts b/packages/app/test/ticket-prompt.test.ts index 4fc31b18..819f2e76 100644 --- a/packages/app/test/ticket-prompt.test.ts +++ b/packages/app/test/ticket-prompt.test.ts @@ -33,4 +33,14 @@ Create \`WHOA.md\` with \`it works!\`.`); }, "bug-fixes"); expect(prompt).toBe("bug-fixes: GEN-1979 — Use `extra` context. (2026.09)"); }); + + it("decodes HTML entities in ticket content before rendering the prompt", () => { + const prompt = linearTicketPrompt({ + identifier: "GEN-2063", title: "Run prompt formatting", + description: "Fix the merge conflicts in https://github.com/GenerationSoftware/factorize/pull/100 & keep the link.", + }, "flow"); + + expect(prompt).toContain("https://github.com/GenerationSoftware/factorize/pull/100 & keep the link."); + expect(prompt).not.toContain("/"); + }); });