Write Gitlink-approved file content byte-for-byte (no newline translation)#92
Merged
Merged
Conversation
…tion) apply_change_set wrote the approved content with write_text's default newline handling, which translates on write: on Windows \n becomes \r\n and an existing \r\n becomes \r\r\n. The file that landed on disk therefore diverged from exactly what the user approved in the preview - and the approval preview diffs via splitlines() (line-ending-agnostic), so the drift never showed. Demonstrated on Windows: approved b"a\nb\r\nc\n" was written as b"a\r\nb\r\r\nc\r\n" (note the CR-CR-LF). The rollback path one block down already restored byte-exact via write_bytes, so a restore was paradoxically more faithful than the original apply. Pass newline="" so the content is written exactly as approved. Regression tests assert the on-disk BYTES (read_text would mask this by translating newlines back on read). Full suite 1694 passed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jul 22, 2026
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.
Summary
apply_change_setwrote approved file content withwrite_text's default newline handling, which translates on write: on Windows\nbecomes\r\nand an existing\r\nbecomes\r\r\n. So the file that lands on disk diverges from exactly what the user approved — and the approval preview diffs viasplitlines()(line-ending-agnostic), so the drift was invisible.Demonstrated on Windows: approved
b"a\nb\r\nc\n"was written asb"a\r\nb\r\r\nc\r\n"(note the doubled\r\r\n). Tellingly, the rollback path one block down already restored byte-exact viawrite_bytes— so a restore was more faithful than the original apply.Fix
Pass
newline=""towrite_textso the approved content is written exactly, byte-for-byte. One line; the rest is a comment and tests.Test plan
read_text()would mask this by translating newlines back on read, so they useread_bytes(): a mixed\n/\r\npayload round-trips exactly and never contains\r\r\n; an LF-only update stays LF.Second of the fixes from the recent adversarial bug-scan (after #91).