Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 17, 2025

Summary

This PR attempts to address Issue #8069 by removing HTML entity unescaping from diff and file operation tools. Feedback and guidance are welcome.

Problem

When applying changes, encoded characters like &, <, and > were being unescaped during diff/search/replace operations, leading to unintended edits and broken code or markup.

Solution

  • Removed unescapeHtmlEntities calls from applyDiffTool.ts
  • Removed unescapeHtmlEntities calls from multiApplyDiffTool.ts
  • Removed unescapeHtmlEntities calls from writeToFileTool.ts
  • Updated tests to verify HTML entities are preserved

Changes

  • src/core/tools/applyDiffTool.ts: Removed HTML entity unescaping
  • src/core/tools/multiApplyDiffTool.ts: Removed HTML entity unescaping
  • src/core/tools/writeToFileTool.ts: Removed HTML entity unescaping
  • src/core/tools/tests/writeToFileTool.spec.ts: Updated tests to verify entities are preserved

Testing

  • Existing tests pass successfully
  • Updated test cases verify that HTML entities are preserved for all models

Impact

This ensures that encoded characters are preserved exactly as written during diff and file operations, preventing unintended modifications to code and markup.

Fixes #8069


Important

Preserve HTML entities in diff, search, and replace operations by removing unescaping calls from key tools and updating tests.

  • Behavior:
    • Removed unescapeHtmlEntities calls from applyDiffTool.ts, multiApplyDiffTool.ts, and writeToFileTool.ts to preserve HTML entities during operations.
    • Updated tests in writeToFileTool.spec.ts to verify HTML entities are preserved.
  • Testing:
    • Existing tests pass successfully.
    • Updated test cases ensure HTML entities are preserved for all models.
  • Impact:
    • Ensures encoded characters are preserved during diff and file operations, preventing unintended modifications to code and markup.

This description was created by Ellipsis for 662c40b. You can customize this summary. It will automatically update as commits are pushed.

- Remove HTML entity unescaping from applyDiffTool.ts
- Remove HTML entity unescaping from multiApplyDiffTool.ts
- Remove HTML entity unescaping from writeToFileTool.ts
- Update tests to verify HTML entities are preserved
- Add comprehensive test suite for HTML entity preservation

This ensures that encoded characters like &, <, and > are preserved
exactly as written during diff and file operations, preventing unintended
modifications to code and markup.

Fixes #8069
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 17, 2025 14:27
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Sep 17, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 17, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.

if (diffContent && !cline.api.getModel().id.includes("claude")) {
diffContent = unescapeHtmlEntities(diffContent)
}
// HTML entities should be preserved exactly as provided
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change to preserve HTML entities. However, I notice that executeCommandTool.ts still uses unescapeHtmlEntities. Is this intentional? Shell commands might need actual characters like < and > for redirection, but it would be good to document why command execution needs different handling than file operations.

})

it("unescapes HTML entities for non-Claude models", async () => {
it("preserves HTML entities for all models", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a test case that specifically reproduces the original issue from #8069? The current test verifies that entities are preserved, but it would be helpful to have a test that demonstrates the actual bug scenario (e.g., applying a diff with < that was incorrectly becoming <).

content: item.content ? unescapeHtmlEntities(item.content) : item.content,
}))
: diffItems
// HTML entities should be preserved exactly as provided
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment style here is slightly different from the one in applyDiffTool.ts (2 lines vs 3 lines). Consider using consistent formatting across files for better readability.

if (!cline.api.getModel().id.includes("claude")) {
newContent = unescapeHtmlEntities(newContent)
}
// HTML entities should be preserved exactly as provided
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see HTML entities being preserved here as well. This ensures consistency across all file write operations.

@daniel-lxs
Copy link
Member

#8069 (comment)

@daniel-lxs daniel-lxs closed this Sep 19, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 19, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG] Diff/search/replace alters HTML entities (unexpected code changes)

4 participants