-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: add option to preserve html entities #8501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { describe, it, expect } from "vitest" | ||
import { unescapeHtmlEntities } from "../text-normalization" | ||
|
||
describe("HTML Entity Preservation", () => { | ||
describe("unescapeHtmlEntities", () => { | ||
it("should unescape basic HTML entities", () => { | ||
expect(unescapeHtmlEntities("<div>")).toBe("<div>") | ||
expect(unescapeHtmlEntities("&")).toBe("&") | ||
expect(unescapeHtmlEntities(""")).toBe('"') | ||
expect(unescapeHtmlEntities("'")).toBe("'") | ||
}) | ||
|
||
it("should handle complex HTML with multiple entities", () => { | ||
const input = "<a href="https://example.com?param1=value&param2=value">Link</a>" | ||
const expected = '<a href="https://example.com?param1=value¶m2=value">Link</a>' | ||
expect(unescapeHtmlEntities(input)).toBe(expected) | ||
}) | ||
|
||
it("should preserve text without entities", () => { | ||
const text = "Plain text without entities" | ||
expect(unescapeHtmlEntities(text)).toBe(text) | ||
}) | ||
|
||
it("should handle empty or undefined input", () => { | ||
expect(unescapeHtmlEntities("")).toBe("") | ||
expect(unescapeHtmlEntities(undefined as unknown as string)).toBe(undefined) | ||
}) | ||
|
||
it("should unescape square bracket entities", () => { | ||
expect(unescapeHtmlEntities("array[0]")).toBe("array[0]") | ||
expect(unescapeHtmlEntities("string[]")).toBe("string[]") | ||
}) | ||
}) | ||
|
||
describe("Setting-based HTML entity handling", () => { | ||
it("should document that preserveHtmlEntities=false triggers unescaping", () => { | ||
// When preserveHtmlEntities is false (default for non-Claude models), | ||
// HTML entities should be unescaped | ||
const input = "<test>" | ||
const output = unescapeHtmlEntities(input) | ||
expect(output).toBe("<test>") | ||
}) | ||
|
||
it("should document that preserveHtmlEntities=true skips unescaping", () => { | ||
// When preserveHtmlEntities is true, the content should remain as-is | ||
// This is tested by NOT calling unescapeHtmlEntities | ||
const input = "<test>" | ||
// In actual usage, when preserveHtmlEntities=true, we skip calling unescapeHtmlEntities | ||
expect(input).toBe("<test>") | ||
}) | ||
|
||
it("should handle code with HTML-like syntax", () => { | ||
const codeWithHtml = "if (x < 10 && y > 5) { return true; }" | ||
const expected = "if (x < 10 && y > 5) { return true; }" | ||
expect(unescapeHtmlEntities(codeWithHtml)).toBe(expected) | ||
}) | ||
|
||
it("should handle XML/JSX code", () => { | ||
const jsx = "<Component prop="value">{children}</Component>" | ||
const expected = '<Component prop="value">{children}</Component>' | ||
expect(unescapeHtmlEntities(jsx)).toBe(expected) | ||
}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P3] The HTML-entity handling condition is duplicated across multiple tools (applyDiffTool, multiApplyDiffTool, writeToFileTool, executeCommandTool). Consider extracting a small shared helper, e.g., shouldUnescapeHtmlEntities({ preserveHtmlEntities, modelId }), to keep behavior consistent and prevent drift.