mirror of
https://github.com/esengine/DeepSeek-Reasonix.git
synced 2026-11-07 10:45:59 -10:00
Merge pull request #14907 from kevin9327/fix/bounded-segment-rune
fix(evidence): cut quoted mutation-scan segments on a rune boundary
This commit is contained in:
2 files changed
+35
-1
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package evidence
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func TestBoundedSegmentCutsOnRuneBoundary(t *testing.T) {
|
||||
// 120 bytes into this segment falls inside a three-byte character.
|
||||
segment := `python3 -c "print('` + strings.Repeat("测试", 30) + `')"`
|
||||
got := boundedSegment(segment)
|
||||
if !utf8.ValidString(got) {
|
||||
t.Fatalf("boundedSegment split a character: %q", got)
|
||||
}
|
||||
kept := strings.TrimSuffix(got, "…")
|
||||
if kept == got || !strings.HasPrefix(segment, kept) {
|
||||
t.Fatalf("boundedSegment = %q, want a prefix of the segment ending in …", got)
|
||||
}
|
||||
if len(kept) > unprovenSegmentLimit || len(kept) < unprovenSegmentLimit-3 {
|
||||
t.Fatalf("boundedSegment kept %d bytes, want just under %d", len(kept), unprovenSegmentLimit)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBoundedSegmentKeepsShortSegment(t *testing.T) {
|
||||
if got := boundedSegment(" python -c 'print(1)' "); got != "python -c 'print(1)'" {
|
||||
t.Fatalf("boundedSegment = %q", got)
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package evidence
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"reasonix/internal/base/shellparse"
|
||||
)
|
||||
@@ -113,7 +114,11 @@ func namedInlineNonTerminalPair(args json.RawMessage) (string, string) {
|
||||
func boundedSegment(segment string) string {
|
||||
segment = strings.TrimSpace(segment)
|
||||
if len(segment) > unprovenSegmentLimit {
|
||||
segment = segment[:unprovenSegmentLimit] + "…"
|
||||
cut := unprovenSegmentLimit
|
||||
for cut > 0 && !utf8.RuneStart(segment[cut]) {
|
||||
cut--
|
||||
}
|
||||
segment = segment[:cut] + "…"
|
||||
}
|
||||
return segment
|
||||
}
|
||||
Reference in new issue
Block a user