fix: truncate preview message text on rune boundary#10
Merged
Conversation
renderPreview capped each message at 500 bytes via text[:500]. A message of multibyte text (CJK, emoji) cut at byte 500 splits a rune and emits invalid UTF-8 into the preview. Slice on runes instead. Same class as the rune-safety fix in #4, but a separate call site in the preview path.
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.
What
renderPreviewcapped each message at 500 bytes withtext[:500]. A message of multibyte text (CJK, emoji) cut at byte 500 splits a rune and emits invalid UTF-8 into the preview pane.Same bug class as #4 (rune-safe
truncate/padRight/highlight), but a separate call site in the preview that #4 didn't touch. Slices on runes now.Tests
TestRenderPreviewLongMultibyteMessageStaysValidUTF8- renders a preview of an 800-rune multibyte message and asserts the output is valid UTF-8 (fails under the old byte slice).go test -cover= 69.1%.