Fix bd-17d5: conflict marker false positives on JSON-encoded content

- import.go: Check raw bytes before JSON decoding using bytes.HasPrefix
- validate.go: Use bytes.Split and bytes.HasPrefix on raw data
- Added regression test TestAutoImportConflictMarkerFalsePositive
- Verified with vc-85 issue that triggered the bug

Amp-Thread-ID: https://ampcode.com/threads/T-3f81e22a-14b9-435b-8932-5641aadb7d31
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-11-08 13:09:26 -08:00
parent 53c9e9bf89
commit 0b28bfec7a
3 changed files with 95 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
package main
import (
"bytes"
"context"
"fmt"
"os"
@@ -324,14 +325,15 @@ func validateGitConflicts(_ context.Context, fix bool) checkResult {
result.err = fmt.Errorf("failed to read JSONL: %w", err)
return result
}
// Look for git conflict markers
lines := strings.Split(string(data), "\n")
// Look for git conflict markers in raw bytes (before JSON decoding)
// This prevents false positives when issue content contains these strings
lines := bytes.Split(data, []byte("\n"))
var conflictLines []int
for i, line := range lines {
trimmed := strings.TrimSpace(line)
if strings.HasPrefix(trimmed, "<<<<<<< ") ||
trimmed == "=======" ||
strings.HasPrefix(trimmed, ">>>>>>> ") {
trimmed := bytes.TrimSpace(line)
if bytes.HasPrefix(trimmed, []byte("<<<<<<< ")) ||
bytes.Equal(trimmed, []byte("=======")) ||
bytes.HasPrefix(trimmed, []byte(">>>>>>> ")) {
conflictLines = append(conflictLines, i+1)
}
}