Skip to content

fix: char-safe table cell truncation - #677

Merged
platinummonkey merged 1 commit into
mainfrom
dd/fix/table-multibyte-truncation-20260727
Jul 27, 2026
Merged

fix: char-safe table cell truncation#677
platinummonkey merged 1 commit into
mainfrom
dd/fix/table-multibyte-truncation-20260727

Conversation

@platinummonkey

@platinummonkey platinummonkey commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes a panic in the -o table formatter 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 shared truncate_ellipsis helper instead of slicing by byte index.

Motivation

src/formatter.rs truncated 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 makes pup monitors list -o table (and any table with non-ASCII cells: dashboard titles, log messages, incident titles, tags) crash for non-English orgs. comfy_table already 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

  • Add truncate_ellipsis(s, max) helper in src/commands/../formatter.rs (src/formatter.rs) that counts characters and cuts on char boundaries, appending ... when shortened.
  • Replace the three byte-index truncation sites in format_cell (string and array paths) and format_array_item with calls to the helper.
  • Add regression tests: a long accented monitor-name string (the exact value from the report) and an accented array-preview value, asserting no panic and correct character-count truncation.

Additional Notes

Existing ASCII behavior is unchanged (byte length equals char count), so prior tests and outputs are preserved. Full cargo test/clippy could not be executed in the sandbox because the datadog-api-client git dependency is unreachable; the truncation logic and test assertions were verified with a standalone rustc build and rustfmt --check passes on the file.

Checklist

  • The code change follows the project conventions (see CONTRIBUTING.md)
  • Tests have been added/updated (if applicable)
  • Documentation has been updated (if applicable)
  • All CI checks pass
  • Code coverage is maintained or improved

Related Issues

Closes #676


PR by Bits - View session in Datadog

Comment @DataDog to request changes

@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Jul 27, 2026

Copy link
Copy Markdown

View session in Datadog

Bits Code status: ✅ Done

Comment @DataDog to request changes

@platinummonkey
platinummonkey requested a review from a team as a code owner July 27, 2026 11:08
@datadog-datadog-prod-us1

Copy link
Copy Markdown
Contributor

I can only run on private repositories.

@platinummonkey
platinummonkey merged commit 3e73026 into main Jul 27, 2026
6 checks passed
@platinummonkey
platinummonkey deleted the dd/fix/table-multibyte-truncation-20260727 branch July 27, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Table formatter panics on multi-byte characters (byte-index truncation)

3 participants