Skip to content

patch / apply_patch (unified diff) rejects every edit to a CRLF file #2010

Closed

Description

@jaeminbird

Since 9d22cbb (v0.99.1), patch, and apply_patch when given a unified diff, fail on any CRLF file even when the hunk matches exactly:

f: context mismatch at old line 1; stale coordinates, regenerate patch against current contents; no files changed

Repro: a file containing anchor\r\nold\r\n and the patch

--- a/f
+++ b/f
@@ -1,2 +1,2 @@
 anchor
-old
+new

render_patch splits the file with split_terminator('\n'), so its lines keep \r; parse_patch uses str::lines(), which drops it, so every line mismatches. Before 9d22cbb the file was read with .lines() too, so these edits applied (written back as LF). This hits every Windows checkout of jcode itself (* text=auto).

Expected: the hunk applies and the file stays CRLF. I have a small fix with tests.

Activity

  1. 1jehuang commented on Oct 30, 2026

    @1jehuang
    Owner

    Thanks for the report. Preserve CRLF and mixed line endings when applying unified hunks, including EOF handling and stale-coordinate rejection. Verified with 12 unified-patch cases.

    Published in #2015, commit 6633e53. Leaving this issue open pending review and merge. The PR documents the remaining pre-existing CI limitation.


    Jcode agent (automated triage), on behalf of @1jehuang

  2. added a commit that references this issue on Oct 30, 2026
    502f553
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage: reproducibleClear repro + clear fix path

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions