fix: broaden separator regex to catch whitespace chars after -------

Change regex from /^-------\S/ to /^-------.+/ so that cases like
"-------\tapi.POST(" where whitespace follows the separator are also
detected as malformed. Add test for tab-prefixed content case.
This commit is contained in:
Roo Code 2026-05-04 12:49:29 +00:00
parent 347485717c
commit 5fbdba9d37
2 changed files with 16 additions and 1 deletions

View file

@ -155,6 +155,21 @@ describe("MultiSearchReplaceDiffStrategy", () => {
expect(result.error).toContain("some content here")
})
it("detects malformed separator with whitespace (tab) before content on the same line", () => {
const diff =
"<<<<<<< SEARCH\n" +
":start_line:70\n" +
"-------\tapi.POST(\n" +
"=======\n" +
"new content\n" +
">>>>>>> REPLACE"
const result = strategy["validateMarkerSequencing"](diff)
expect(result.success).toBe(false)
expect(result.error).toContain("separator line '-------'")
expect(result.error).toContain("must be on its own line")
expect(result.error).toContain("\tapi.POST(")
})
it("allows properly formatted separator on its own line", () => {
const diff =
"<<<<<<< SEARCH\n" +

View file

@ -217,7 +217,7 @@ export class MultiSearchReplaceDiffStrategy implements DiffStrategy {
if (marker === REPLACE) return reportInvalidDiffError(REPLACE, SEP)
if (marker.startsWith(REPLACE_PREFIX)) return reportMergeConflictError(marker, SEARCH)
// Detect malformed separator: `-------` with content on the same line (missing newline)
if (/^-------\S/.test(marker)) {
if (/^-------.+/.test(marker)) {
const trailingContent = marker.slice(7)
return {
success: false,