fix: char-safe table cell truncation - #677
Merged
Merged
Conversation
|
Bits Code status: ✅ Done Comment @DataDog to request changes |
Contributor
|
I can only run on private repositories. |
amaskara-dd
approved these changes
Jul 27, 2026
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 does this PR do?
Fixes a panic in the
-o tableformatter when a cell value longer than the column cap is cut inside a multi-byte UTF-8 character. Cell truncation now cuts on character boundaries via a sharedtruncate_ellipsishelper instead of slicing by byte index.Motivation
src/formatter.rstruncated table cells with byte-index slices (&s[..47],&s[..13],&result[..47]). Any value whose cut point landed inside a multi-byte character panicked, e.g.end byte index 47 is not a char boundary; it is inside 'è'. This makespup monitors list -o table(and any table with non-ASCII cells: dashboard titles, log messages, incident titles, tags) crash for non-English orgs.comfy_tablealready handles display-width column alignment, so a character-boundary cap is sufficient to both stop the panic and keep alignment correct — no new dependency required. Closes #676.Changes
truncate_ellipsis(s, max)helper insrc/commands/../formatter.rs(src/formatter.rs) that counts characters and cuts oncharboundaries, appending...when shortened.format_cell(string and array paths) andformat_array_itemwith calls to the helper.Additional Notes
Existing ASCII behavior is unchanged (byte length equals char count), so prior tests and outputs are preserved. Full
cargo test/clippycould not be executed in the sandbox because thedatadog-api-clientgit dependency is unreachable; the truncation logic and test assertions were verified with a standalonerustcbuild andrustfmt --checkpasses on the file.Checklist
Related Issues
Closes #676
PR by Bits - View session in Datadog
Comment @DataDog to request changes