fix(filesystem): ignore trailing newline in tail - #4674
Open
jstar0 wants to merge 1 commit into
Open
Conversation
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.
Description
Fix
tailFileso a file's final newline is treated as a line terminator rather than an additional empty line. This makestail=1return the final content line for files that end with\nor\r\n.Server Details
Motivation and Context
When a file ends with a newline, the reverse chunk reader currently includes the synthetic empty segment after that terminator. Callers requesting the last line therefore receive an empty string instead of the final content line. The fix removes that synthetic segment only for the first chunk read from the end; line handling and chunk-boundary behavior remain unchanged.
How Has This Been Tested?
npm exec --workspace @modelcontextprotocol/server-filesystem -- vitest run __tests__/lib.test.ts --reporter=dot— 47 passednpm run build --workspace @modelcontextprotocol/server-filesystem— passedThe regression covers a file containing
line1\nline2\nand verifies thattailFile(path, 1)returnsline2and closes the file handle.Breaking Changes
No. This corrects the returned value for files ending in a newline; files without a trailing newline retain their existing behavior.
Types of changes
Checklist
Additional context
The change is limited to the filesystem server's existing tail operation and adds no protocol, configuration, or dependency changes.