Skip to content

fix: keep a CRLF file's line endings in filesystem-edit-file - #6756

Open
MohammadHijjawi97 wants to merge 1 commit into
Mintplex-Labs:masterfrom
MohammadHijjawi97:fix/filesystem-edit-keep-crlf
Open

MohammadHijjawi97 wants to merge 1 commit into
Mintplex-Labs:masterfrom
MohammadHijjawi97:fix/filesystem-edit-keep-crlf

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown
Contributor

Pull Request Type

  • ✨ feat (New feature)
  • 🐛 fix (Bug fix)
  • ♻️ refactor (Code refactoring without changing behavior)
  • 💄 style (UI style changes)
  • 🔨 chore (Build, CI, maintenance)
  • 📝 docs (Documentation updates)

Relevant Issues

resolves #6755

Description

applyFileEdits normalizes the file's CRLF line endings to LF before matching edits, then writes that normalized text back. Every edit to a CRLF file therefore rewrote the whole file with LF line endings, while the returned diff (computed on the normalized text) showed only the edited lines.

The file is now written back with its predominant line ending: CRLF when more of its line breaks are CRLF than LF, otherwise LF. This is the same rule the upstream MCP filesystem server adopted for the same bug (modelcontextprotocol/servers#5011). Matching, the returned diff and dry runs are unchanged.

Editing port=3000 to port=8080 in "[server]\r\nport=3000\r\nhost=localhost\r\n":

  • before: "[server]\nport=8080\nhost=localhost\n"
  • after: "[server]\r\nport=8080\r\nhost=localhost\r\n"

Visuals (if applicable)

N/A

Additional Information

server/__tests__/utils/agents/aibitat/plugins/filesystem/lib.test.js edits temp files and checks the bytes written: a CRLF file (exact and whitespace-tolerant match), an LF file edited with CRLF newText, a mixed file, and a dry run. The three CRLF cases fail without the change. Happy to drop the test file if you prefer to keep this to the fix only. eslint on the changed file is clean.

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated (if applicable)
  • I have tested my code functionality
  • Docker build succeeds locally

applyFileEdits matched edits on LF-normalized text and wrote that text back, so any edit to a CRLF file converted every line to LF while the returned diff showed only the edited lines. Write the file back with its predominant line ending, as the upstream MCP filesystem server does since modelcontextprotocol/servers#5011.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: filesystem-edit-file converts a CRLF file's line endings to LF on every edit

1 participant