Skip to content

[Bug] diff_edit fails to match SEARCH blocks on CRLF files #1993

Open

Description

@Mahdi-Hasan

Description

diff_edit refuses edits to files with CRLF line endings. Models send SEARCH blocks with LF line breaks, and countOccurrences / applyBlocks in source/tools/file-ops/diff-edit.tsx match block.search literally, so a multi-line SEARCH block never matches a CRLF file.

This is the third file editor with the CRLF problem from #1964. string_replace is fixed in #1961 (#1930) and write_file in #1992 (#1964). The nc-review bot on #1992 asked for a follow-up issue so diff_edit is not lost when #1964 closes.

Environment

  • OS: Windows 11
  • Node version: v24.16.0
  • Nanocoder version: 1.32.0 (main at 49ff6fe)
  • Provider: n/a, reproduced by calling the tool directly
  • Model: n/a

Steps to Reproduce

  1. Create a file with CRLF line endings: one\r\ntwo\r\nthree\r\n.
  2. Run diff_edit on it with an LF SEARCH block:
    <<<<<<< SEARCH
    one
    two
    =======
    one
    TWO
    >>>>>>> REPLACE
    

Expected Behavior

The block matches and the file becomes one\r\nTWO\r\nthree\r\n, still CRLF.

Actual Behavior

Search block 1 was not found in file. The file may have changed since you last read it. The file is unchanged.

Logs/Screenshots

n/a

Additional Context

Possible fix: reuse fitEditToLineEndings(fileContent, block.search, block.replace) from source/utils/line-endings.ts (added in #1961) in validateBlocks, applyBlocks and the preview. I'd like to take this once #1961 lands, if a maintainer assigns it to me. I'll wait for that before opening a PR.

  • I have searched existing issues to ensure this is not a duplicate
  • I can reproduce this issue consistently
  • This issue occurs with the latest version of nanocoder

Activity

  1. added
    needs-triage
    area:tools
    bug
    good first issue
    and removed
    needs-triage
    on Nov 7, 2026
  2. Edzard9 commented on Nov 7, 2026

    @Edzard9

    Hi, I'd like to take this one. I'm on Windows myself and hit CRLF issues regularly. Plan: apply the same line-ending normalization used in the string_replace (#1961) and write_file (#1992) fixes to diff_edit's SEARCH matching, preserving the file's original CRLF endings when writing.

  3. Mahdi-Hasan commented on Nov 7, 2026

    @Mahdi-Hasan
    ContributorAuthor

    Thanks @Edzard9. I filed this as a follow-up to #1964 and asked in the description to take it once #1961 landed. #1961 is now merged, so I'm ready to start: fit each SEARCH/REPLACE block with fitEditToLineEndings in validateBlocks, applyBlocks and the preview, plus a CRLF spec. @addyCooks, your call on who takes it. I'll wait for assignment before opening a PR.

  4. addyCooks commented on Nov 10, 2026

    @addyCooks
    Collaborator

    Thanks all for the interest! @Mahdi-Hasan filed this and asked first (and wrote the sibling fixes in #1961/#1992), so I'm assigning it to them.

    @Edzard9 @SatriaBagusNurhadianto, thanks for the PRs (#1995, #1994). Since the issue was already requested, we'll go with Mahdi's, so please close yours. Going forward, please comment on an issue and wait for assignment before opening a PR.
    Feel free to pick up another open issue.

  5. added 2 commits that reference this issue on Nov 12, 2026
    fec5e64
    0ee34ca
  6. added a commit that references this issue on Nov 26, 2026
    c3bdfee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:toolsbuggood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions