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:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -96,15 +97,20 @@ NOTE: Import requires direct database access and does not work with daemon mode.
|
||||
|
||||
for scanner.Scan() {
|
||||
lineNum++
|
||||
line := scanner.Text()
|
||||
rawLine := scanner.Bytes()
|
||||
line := string(rawLine)
|
||||
|
||||
// Skip empty lines
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Detect git conflict markers and attempt automatic 3-way merge
|
||||
if strings.Contains(line, "<<<<<<<") || strings.Contains(line, "=======") || strings.Contains(line, ">>>>>>>") {
|
||||
// Detect git conflict markers in raw bytes (before JSON decoding)
|
||||
// This prevents false positives when issue content contains these strings
|
||||
trimmed := bytes.TrimSpace(rawLine)
|
||||
if bytes.HasPrefix(trimmed, []byte("<<<<<<< ")) ||
|
||||
bytes.Equal(trimmed, []byte("=======")) ||
|
||||
bytes.HasPrefix(trimmed, []byte(">>>>>>> ")) {
|
||||
fmt.Fprintf(os.Stderr, "Git conflict markers detected in JSONL file (line %d)\n", lineNum)
|
||||
fmt.Fprintf(os.Stderr, "→ Attempting automatic 3-way merge...\n\n")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user