Skip to content

fix(viewer): truncate multibyte file paths on rune boundaries - #1854

Merged
lizhengfeng101 merged 3 commits into
alibaba:mainfrom
LuckVd:fix/1853-truncate-multibyte-rune
Nov 16, 2026
Merged

lizhengfeng101 merged 3 commits into
alibaba:mainfrom
LuckVd:fix/1853-truncate-multibyte-rune

Conversation

@LuckVd

@LuckVd LuckVd commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #1853

The viewer's truncateText limited 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

  • Count and slice Unicode runes in internal/viewer/server.go:478-484.
  • Cover an actual mid-rune cut and assert valid UTF-8 across multiple scripts and cut lengths in internal/viewer/server_test.go:25-60.

Type of Change

  • 🐛 Bug fix

Related Issue

Testing

  • go test -race -count=1 ./internal/viewer — pass
  • go build ./internal/viewer — pass
  • go vet ./internal/viewer — clean
  • gofmt -l internal/viewer/server.go internal/viewer/server_test.go — no output
  • git diff --check origin/main...HEAD — clean
  • Full-repository make 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...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages/components pass
  • Diff-scoped lint passes where applicable
  • Full-repository checks were run (not run locally; see Testing)
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Breaking changes are clearly called out in the description above (none)

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
@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

@chaojixinren chaojixinren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. #1852 fixes the same issue in scan summaries; this PR fixes it in viewer paths. make test passed.

@LuckVd

LuckVd commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

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 NanaseInori left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 783fa67 into alibaba:main Nov 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(viewer): truncateText splits multibyte file paths mid-rune

4 participants