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:
YHH authored and GitHub committed 2026-11-01 06:22:45 -08:00
commit f88faddf41
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)
}
}
+6 -1
View File
@@ -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
}