Repository navigation
fix(viewer): truncate multibyte file paths on rune boundaries - #1854
Conversation
truncateText sliced the input by bytes (s[:n]), which split multibyte UTF-8 runes mid-sequence when a file path contained CJK, Cyrillic or emoji characters. The broken bytes reached the rendered session task table (session.html truncates FilePath at 60) and browsers displayed U+FFFD replacement characters. Switch to the rune-based truncation pattern already used in internal/agent/util.go and internal/session/manifest.go, so the truncate template function always emits valid UTF-8. Replace the on-boundary-only unicode fixture with cases that genuinely cut inside a multibyte rune, and add TestTruncateTextAlwaysValidUTF8 covering CJK, Cyrillic and emoji inputs across cut widths. Fixes alibaba#1853
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
chaojixinren
left a comment
There was a problem hiding this comment.
LGTM. #1852 fixes the same issue in scan summaries; this PR fixes it in viewer paths. make test passed.
|
Hi maintainers — thanks for the approval and for the successful code-review / CLA checks. GitHub still shows REVIEW_REQUIRED / BLOCKED. Is another approval or any action from me needed before this can proceed? |
NanaseInori
left a comment
There was a problem hiding this comment.
Reviewed both changed files, #1853 and the existing review discussion. The issue-number search returned only this PR. #1852 concerns the separate scan-summary formatter; it does not fix the viewer helper changed here.
The previous byte slice can split a valid multibyte pathname. Counting and slicing runes eliminates that corruption for valid UTF-8 input, preserves ASCII and zero-length truncation behavior, and makes the display limit a rune count rather than a byte count. The regression now includes an actual mid-rune boundary instead of only a byte offset divisible by three. No blocking defect found in this focused display-only fix.
I ran an isolated Go harness using this helper's exact new algorithm: all five script/path fixtures over n=0..12 produced the expected valid UTF-8 results, and the old n=5 byte slice reproduced invalid UTF-8. This does not claim grapheme-cluster/display-column truncation, browser testing, or an independent run of the repository suite.
This review was conducted by NanaseInori's review bot, using the model GPT-6 Astra Pro. If you need a human review, please manually @NanaseInori.
Description
Fixes #1853
The viewer's
truncateTextlimited file paths by UTF-8 byte count, so truncation could split a multibyte rune and emit invalid UTF-8. I changed it to truncate on rune boundaries, following existing project patterns, and added regression tests for multibyte cuts and UTF-8 validity across CJK, Cyrillic, and emoji input.Change
internal/viewer/server.go:478-484.internal/viewer/server_test.go:25-60.Type of Change
Related Issue
Testing
go test -race -count=1 ./internal/viewer— passgo build ./internal/viewer— passgo vet ./internal/viewer— cleangofmt -l internal/viewer/server.go internal/viewer/server_test.go— no outputgit diff --check origin/main...HEAD— cleanmake test/ CI suite was not run locally; local verification was scoped to the changed package. The repository CI will provide the full-suite check.Checklist
git diff --check origin/main...HEADpasses