Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/utils/__tests__/sanitize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("<a>foo>bar")).toBe("foo>bar");
expect(sanitizeForPrompt("<b>hello</b> world")).toBe("hello world");
});

it("should handle malformed tags", () => {
const input = "Text <incomplete";
expect(sanitizeForPrompt(input)).toBe("Text <incomplete");
Expand Down Expand Up @@ -821,6 +826,10 @@ describe("sanitizeForContext", () => {
});

describe("sanitizeTaskDescription", () => {
it("should preserve plain text after a tag when it is followed by >", () => {
expect(sanitizeTaskDescription("<a>foo>bar")).toBe("foo>bar");
});

it("should remove fragmented nested script tags", () => {
const input = "<scrip<script>t>alert(1)</scrip<script>t>";
const result = sanitizeTaskDescription(input);
Expand Down
16 changes: 9 additions & 7 deletions src/utils/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading