Skip to content

Commit dd2483f

Browse files
committed
fix(native): escape markers in edit_file
1 parent 52aedf2 commit dd2483f

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

lua/mcphub/native/neovim/files/edit_file/diff_parser.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ end
295295

296296
function DiffParser:unescape_markers(line)
297297
local newline = line:gsub("^%s*\\<<<<<", "<<<<<<"):gsub("^%s*\\=====", "====="):gsub("^%s*\\>>>>>", ">>>>>")
298+
newline = newline:gsub("^%s*\\\\<<<<<", "<<<<<<"):gsub("^%s*\\\\=====", "====="):gsub("^%s*\\\\>>>>>", ">>>>>")
298299
return newline
299300
end
300301

lua/mcphub/native/neovim/files/edit_file/init.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ IMPORTANT: The tool is NEVER wrong. Once edits are shown in the buffer, user mig
3939
CRITICAL:
4040
- When there are two or more related changes needed in a file, always use multiple SEARCH/REPLACE blocks in the diff from the start of the file to the end. Each block should contain the exact content to find and the new content to replace it with. Failing to do so or using multiple calls with single SEARCH/REPLACE block will result in you being fired!!!
4141
- The markers `<<<<<<< SEARCH`, `=======`, and `>>>>>>> REPLACE` MUST be exact with no other characters on the line.
42-
- When the SEARCH or REPLACE content includes lines that start with markers like `<<<<<<<`, `=======`, or `>>>>>>>`, you MUST escape them by adding a backslash before each marker so that tool doesn't parse them as actual markers. For example, to search for content that has `<<<<<<< SEARCH`, use `\<<<<<<< SEARCH` in the SEARCH block.
4342
4443
4544
Examples:
@@ -112,6 +111,9 @@ print("Count is", count)
112111
print("Counter is", counter)
113112
>>>>>>> REPLACE
114113
114+
CRITICAL RULE:
115+
When the SEARCH or REPLACE content includes lines that start with markers like `<<<<<<<`, `=======`, or `>>>>>>>`, you MUST escape them by adding a backslash before each marker so that tool doesn't parse them as actual markers. For example, to search for content that has `<<<<<<< SEARCH`, use `\<<<<<<< SEARCH` in the SEARCH block.
116+
115117
5. Escaping markers in SEARCH/REPLACE content:
116118
<<<<<<< SEARCH
117119
Tutorial:

tests/native/neovim/files/edit_file/test_diff_parser.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ local y = 3
196196
eq(error, nil)
197197
eq(#blocks, 1)
198198
local block = blocks[1]
199-
eq(block.search_lines[2] == "<<<<<<<< SEARCH", true)
199+
eq(block.search_lines[2], "<<<<<<<< SEARCH")
200200
end
201201

202202
-- Group 2: Malformed Input and Issue Tracking

0 commit comments

Comments
 (0)