Skip to content

Write Gitlink-approved file content byte-for-byte (no newline translation)#92

Merged
dovvnloading merged 1 commit into
mainfrom
hotfix/gitlink-apply-line-endings
Jul 22, 2026
Merged

Write Gitlink-approved file content byte-for-byte (no newline translation)#92
dovvnloading merged 1 commit into
mainfrom
hotfix/gitlink-apply-line-endings

Conversation

@dovvnloading

Copy link
Copy Markdown
Owner

Summary

apply_change_set wrote approved file 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. So the file that lands on disk diverges from exactly what the user approved — and the approval preview diffs via splitlines() (line-ending-agnostic), so the drift was invisible.

Demonstrated on Windows: approved b"a\nb\r\nc\n" was written as b"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 via write_bytes — so a restore was more faithful than the original apply.

Fix

Pass newline="" to write_text so the approved content is written exactly, byte-for-byte. One line; the rest is a comment and tests.

Test plan

  • Regression tests assert the on-disk bytesread_text() would mask this by translating newlines back on read, so they use read_bytes(): a mixed \n/\r\n payload round-trips exactly and never contains \r\r\n; an LF-only update stays LF.
  • Full suite: 1694 passed, zero regressions
  • Confirmed on Windows that the pre-fix code produced the CR-CR-LF corruption and the fix writes byte-exact

Second of the fixes from the recent adversarial bug-scan (after #91).

…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>
@dovvnloading
dovvnloading merged commit 5d0b027 into main Jul 22, 2026
2 checks passed
@dovvnloading
dovvnloading deleted the hotfix/gitlink-apply-line-endings branch July 22, 2026 00:53
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.

1 participant