fix: avoid panic when truncating summaries at a multi-byte char boundary - #2
Open
brkastner wants to merge 1 commit into
Open
fix: avoid panic when truncating summaries at a multi-byte char boundary#2brkastner wants to merge 1 commit into
brkastner wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
truncate_summary()slicedtrimmed[..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.max_lenoff to the nearest precedingis_char_boundarybefore slicing.Fixes #1.
Test plan
cargo test --lib truncate— all 6 related tests pass, including the newtest_truncate_summary_multibyte_char_at_boundarycargo fmt --checkon the changed fileacp annotateagainst the file that originally triggered the panic — completes cleanly now