fix: remove HTML entity unescaping for non-Claude models to preserve C# generics

- Removed unescapeHtmlEntities call that was converting angle brackets in C# generic types
- This fixes issue #6770 where C# code like Configure<BlazorServerSettings> was being incorrectly converted to Configure<BlazorServerSettings>
- Updated tests to verify C# generics and angle brackets are preserved correctly
This commit is contained in:
Roo Code 2025-08-06 21:07:40 +00:00
parent c52fdc4397
commit fe9811d188
2 changed files with 16 additions and 20 deletions

View file

@ -6,7 +6,6 @@ import { fileExistsAtPath } from "../../../utils/fs"
import { detectCodeOmission } from "../../../integrations/editor/detect-omission"
import { isPathOutsideWorkspace } from "../../../utils/pathUtils"
import { getReadablePath } from "../../../utils/path"
import { unescapeHtmlEntities } from "../../../utils/text-normalization"
import { everyLineHasLineNumbers, stripLineNumbers } from "../../../integrations/misc/extract-text"
import { ToolUse, ToolResponse } from "../../../shared/tools"
import { writeToFileTool } from "../writeToFileTool"
@ -54,10 +53,6 @@ vi.mock("../../../utils/path", () => ({
getReadablePath: vi.fn().mockReturnValue("test/path.txt"),
}))
vi.mock("../../../utils/text-normalization", () => ({
unescapeHtmlEntities: vi.fn().mockImplementation((content) => content),
}))
vi.mock("../../../integrations/misc/extract-text", () => ({
everyLineHasLineNumbers: vi.fn().mockReturnValue(false),
stripLineNumbers: vi.fn().mockImplementation((content) => content),
@ -104,7 +99,6 @@ describe("writeToFileTool", () => {
const mockedDetectCodeOmission = detectCodeOmission as MockedFunction<typeof detectCodeOmission>
const mockedIsPathOutsideWorkspace = isPathOutsideWorkspace as MockedFunction<typeof isPathOutsideWorkspace>
const mockedGetReadablePath = getReadablePath as MockedFunction<typeof getReadablePath>
const mockedUnescapeHtmlEntities = unescapeHtmlEntities as MockedFunction<typeof unescapeHtmlEntities>
const mockedEveryLineHasLineNumbers = everyLineHasLineNumbers as MockedFunction<typeof everyLineHasLineNumbers>
const mockedStripLineNumbers = stripLineNumbers as MockedFunction<typeof stripLineNumbers>
const mockedPathResolve = path.resolve as MockedFunction<typeof path.resolve>
@ -124,7 +118,6 @@ describe("writeToFileTool", () => {
mockedDetectCodeOmission.mockReturnValue(false)
mockedIsPathOutsideWorkspace.mockReturnValue(false)
mockedGetReadablePath.mockReturnValue("test/path.txt")
mockedUnescapeHtmlEntities.mockImplementation((content) => content)
mockedEveryLineHasLineNumbers.mockReturnValue(false)
mockedStripLineNumbers.mockImplementation((content) => content)
@ -288,20 +281,28 @@ describe("writeToFileTool", () => {
expect(mockCline.diffViewProvider.update).toHaveBeenCalledWith("", true)
})
it("unescapes HTML entities for non-Claude models", async () => {
mockCline.api.getModel.mockReturnValue({ id: "gpt-4" })
it("preserves C# generics and angle brackets in content", async () => {
const csharpContent = `public class Service<T> where T : class
{
public void Configure<TOptions>(TOptions options)
{
builder.Services.Configure<BlazorServerSettings>(builder.Configuration.GetSection("BlazorServerSettings"));
}
}`
await executeWriteFileTool({ content: "&lt;test&gt;" })
await executeWriteFileTool({ content: csharpContent, line_count: "7" })
expect(mockedUnescapeHtmlEntities).toHaveBeenCalledWith("&lt;test&gt;")
// Verify the content is passed through unchanged (no HTML entity conversion)
expect(mockCline.diffViewProvider.update).toHaveBeenCalledWith(csharpContent, true)
})
it("skips HTML unescaping for Claude models", async () => {
mockCline.api.getModel.mockReturnValue({ id: "claude-3" })
it("preserves HTML entities in content without unescaping", async () => {
const contentWithEntities = "This has &lt;angle&gt; brackets and &amp; ampersand"
await executeWriteFileTool({ content: "&lt;test&gt;" })
await executeWriteFileTool({ content: contentWithEntities })
expect(mockedUnescapeHtmlEntities).not.toHaveBeenCalled()
// Verify the content is passed through with HTML entities preserved
expect(mockCline.diffViewProvider.update).toHaveBeenCalledWith(contentWithEntities, true)
})
it("strips line numbers from numbered content", async () => {

View file

@ -13,7 +13,6 @@ import { stripLineNumbers, everyLineHasLineNumbers } from "../../integrations/mi
import { getReadablePath } from "../../utils/path"
import { isPathOutsideWorkspace } from "../../utils/pathUtils"
import { detectCodeOmission } from "../../integrations/editor/detect-omission"
import { unescapeHtmlEntities } from "../../utils/text-normalization"
import { DEFAULT_WRITE_DELAY_MS } from "@roo-code/types"
import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
@ -83,10 +82,6 @@ export async function writeToFileTool(
newContent = newContent.split("\n").slice(0, -1).join("\n")
}
if (!cline.api.getModel().id.includes("claude")) {
newContent = unescapeHtmlEntities(newContent)
}
// Determine if the path is outside the workspace
const fullPath = relPath ? path.resolve(cline.cwd, removeClosingTag("path", relPath)) : ""
const isOutsideWorkspace = isPathOutsideWorkspace(fullPath)