Repository navigation
fix: keep a CRLF file's line endings in filesystem-edit-file - #6756
Open
MohammadHijjawi97 wants to merge 1 commit into
Open
MohammadHijjawi97 wants to merge 1 commit into
MohammadHijjawi97 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Type
Relevant Issues
resolves #6755
Description
applyFileEditsnormalizes 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=3000toport=8080in"[server]\r\nport=3000\r\nhost=localhost\r\n":"[server]\nport=8080\nhost=localhost\n""[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.jsedits temp files and checks the bytes written: a CRLF file (exact and whitespace-tolerant match), an LF file edited with CRLFnewText, 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
yarn lintfrom the root of the repo & committed changes