Skip to content

fix: avoid panic when truncating summaries at a multi-byte char boundary - #2

Open
brkastner wants to merge 1 commit into
acp-protocol:mainfrom
brkastner:fix/truncate-summary-char-boundary
Open

fix: avoid panic when truncating summaries at a multi-byte char boundary#2
brkastner wants to merge 1 commit into
acp-protocol:mainfrom
brkastner:fix/truncate-summary-char-boundary

Conversation

@brkastner

Copy link
Copy Markdown

Summary

  • truncate_summary() sliced trimmed[..max_len] by raw byte offset with no UTF-8 char-boundary check, so any doc-comment summary with a multi-byte character (e.g. box-drawing , U+2500, 3 bytes) straddling byte 100 panicked instead of truncating.
  • Backs max_len off to the nearest preceding is_char_boundary before slicing.
  • Adds a regression test reproducing the exact panicking input from panic: end byte index is not a char boundary in truncate_summary #1.

Fixes #1.

Test plan

  • cargo test --lib truncate — all 6 related tests pass, including the new test_truncate_summary_multibyte_char_at_boundary
  • cargo fmt --check on the changed file
  • Rebuilt the CLI and re-ran acp annotate against the file that originally triggered the panic — completes cleanly now

truncate_summary() sliced trimmed[..max_len] by raw byte offset, which
panics if a multi-byte UTF-8 character (e.g. box-drawing '─', 3 bytes)
straddles that offset. Back off to the nearest preceding char boundary
before slicing.

Fixes acp-protocol#1
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.

panic: end byte index is not a char boundary in truncate_summary

1 participant