nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] diff_edit splits the SEARCH block inside a long line of "=" characters

Open addyCooks opened this issue 2 weeks ago • 2 comments

Description

diff_edit looks for the ======= separator as a plain substring. A line such as ========== (an underline in Markdown or reStructuredText) contains it, so it is treated as the separator. The wrong text is applied and the file is damaged.

Environment

  • OS: Windows 11 Home 10.0.26300
  • Node version: v22.22.3
  • Nanocoder version: 1.32.0 (built from main at f92cce9c)
  • Provider: Not provider-specific
  • Model: Not model-specific

Steps to Reproduce

  1. Create heading.rst containing Title\n==========\n\nBody\n and read it with read_file.

  2. Call diff_edit with this diff:

     <<<<<<< SEARCH
     Title
     ==========
     =======
     New Title
     ==========
     >>>>>>> REPLACE
    

Expected Behavior

The file becomes New Title\n==========\n\nBody\n.

Actual Behavior

The validator says the diff is valid and the file is damaged.

Logs/Screenshots

parseDiffEditBlocks -> [{search: "Title", replace: "===\n=======\nNew Title\n=========="}]
file after: "===\n=======\nNew Title\n==========\n==========\n\nBody\n"

Additional Context

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

Suggested fix:

  • source/tools/file-ops/diff-edit.tsx:100 uses diff.indexOf(SEPARATOR_MARKER, ...). Match the separator only when it is a whole line (for example /^=======$/m), and check the REPLACE marker the same way.
  • Add tests for underlines of 7 or more = characters in both the search and replace parts.

addyCooks avatar Nov 14 '26 06:11 addyCooks

I will pick this up, following the suggested whole-line marker fix. I will cover long equals underlines and marker-looking inline text in SEARCH and REPLACE, including CRLF input, and keep the existing multi-block behavior.

Purv-Kabaria avatar Nov 14 '26 10:11 Purv-Kabaria

I'd like to work on this. #2212 was closed by its author, so I'll pick it up unless they're coming back to it.

KhadeerBasha1232 avatar Nov 28 '26 04:11 KhadeerBasha1232