fix(cli): prevent UTF-8 panic in explore table wrapping (3.2.3)#52
Merged
fix(cli): prevent UTF-8 panic in explore table wrapping (3.2.3)#52
Conversation
`devtrail explore` panicked with `byte index X is not a char boundary`
when rendering Markdown tables whose cells contained multi-byte UTF-8
characters such as em-dash (U+2014, 3 bytes), CJK ideograms, accented
characters or emoji. The cause was `wrap_cell_text()` slicing `&str`
by a byte offset derived from terminal columns.
Fix:
- Rewrite `wrap_cell_text()` to iterate with `char_indices()` so every
slice boundary is a valid char boundary.
- Measure text width with `unicode-width` (added as a direct dep under
the existing `tui` feature; was already a transitive dep of
`ratatui`, so no new compile cost) so wrapping and natural column
widths match the visual columns ratatui reserves at render time.
- Manually pad cells by visual width in `render_table_row()` instead
of `format!("{:<width$}", ...)`, which counts chars, not columns —
this also aligns borders for CJK / double-wide content (relevant for
the zh-CN docs the project ships).
- Add 16 unit tests, including a regression for the exact panic
(`em_dash_no_panic`) and an end-to-end pipeline test using the
literal row that crashed the reported document.
Bump CLI to 3.2.3.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 24, 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.
Summary
devtrail explorepanic (byte index N is not a char boundary) when Markdown tables contain multi-byte UTF-8 characters (em-dash—, CJK, accents, emoji).wrap_cell_text()now iterates withchar_indices()and measures width viaunicode-width, guaranteeing safe slice offsets and correct visual widths.render_table_row()instead offormat!("{:<width$}", ...)(which counts chars, not columns).em_dash_no_panic) that reproduces the original crash and an end-to-end test running the exact table row that triggered it throughmarkdown_to_lines.unicode-width = "0.2"promoted to a direct optional dep under the existingtuifeature (was already transitive viaratatui, so no new compile cost).Reproduction
Running
devtrail exploreon a document containing this table row used to panic:After this patch the view renders the table without panic and with aligned borders.
Test plan
cargo test— 64 library tests passing (48 pre-existing + 16 newtui::markdown::tests::*).cargo build --no-default-features— compiles (feature gate onunicode-widthis respected).cargo build --release— compiles;./target/release/devtrail aboutreportscli-3.2.3.cargo clippy --all-features— no new warnings from this patch (6 pre-existing warnings in files not touched here)../target/release/devtrail explore <path-with-problematic-doc>opens the document without panic.│borders.Files changed
cli/Cargo.toml— bump to 3.2.3, addunicode-widthunder featuretui.cli/Cargo.lock— regenerated (addsunicode-widthas direct dep; same version already present transitively).cli/src/tui/markdown.rs— rewritewrap_cell_text, fix visual-width measurement incompute_column_widthsandrender_table_row, add 16 tests.CHANGELOG.md—## CLI 3.2.3 — UTF-8 Crash Fix in explore Tablessection.README.md,docs/i18n/es/README.md,docs/i18n/zh-CN/README.md— versioning table bump.docs/adopters/CLI-REFERENCE.mdand itses/+zh-CN/mirrors — version refs bumped.🤖 Generated with Claude Code