diff --git a/src/utils/__tests__/sanitize.test.ts b/src/utils/__tests__/sanitize.test.ts index 1936d928..8822b1fa 100644 --- a/src/utils/__tests__/sanitize.test.ts +++ b/src/utils/__tests__/sanitize.test.ts @@ -265,6 +265,11 @@ describe("sanitizeForPrompt", () => { expect(sanitizeForPrompt(input)).toBe("3 < 5 and 7 > 2"); }); + it("should preserve plain text after a tag when it is followed by >", () => { + expect(sanitizeForPrompt("foo>bar")).toBe("foo>bar"); + expect(sanitizeForPrompt("hello world")).toBe("hello world"); + }); + it("should handle malformed tags", () => { const input = "Text { }); describe("sanitizeTaskDescription", () => { + it("should preserve plain text after a tag when it is followed by >", () => { + expect(sanitizeTaskDescription("foo>bar")).toBe("foo>bar"); + }); + it("should remove fragmented nested script tags", () => { const input = "t>alert(1)t>"; const result = sanitizeTaskDescription(input); diff --git a/src/utils/sanitize.ts b/src/utils/sanitize.ts index 100e8645..5b7d8931 100644 --- a/src/utils/sanitize.ts +++ b/src/utils/sanitize.ts @@ -13,13 +13,15 @@ function stripMarkupTags(text: string): string { if (text[i] === "<" && isTagStart(text, i)) { let end = text.indexOf(">", i + 1); if (end !== -1) { - let next = end + 1; - while (next < text.length) { - const fragmentEnd = text.indexOf(">", next); - if (fragmentEnd === -1) break; - if (!isTagNameFragment(text.slice(next, fragmentEnd))) break; - end = fragmentEnd; - next = end + 1; + if (text.slice(i + 1, end).includes("<")) { + let next = end + 1; + while (next < text.length) { + const fragmentEnd = text.indexOf(">", next); + if (fragmentEnd === -1) break; + if (!isTagNameFragment(text.slice(next, fragmentEnd))) break; + end = fragmentEnd; + next = end + 1; + } } i = end; continue;