Skip to content

fix(find): round dir-display truncation up to a char boundary (fixes #2851) - #2852

Closed
Revlochon wants to merge 1 commit into
rtk-ai:developfrom
Revlochon:fix/find-dir-display-utf8-boundary
Closed

Revlochon wants to merge 1 commit into
rtk-ai:developfrom
Revlochon:fix/find-dir-display-utf8-boundary

Conversation

@Revlochon

Copy link
Copy Markdown

Problem

rtk find panics when the grouped-results display truncates a directory path longer than 50 bytes and the raw byte slice &dir[dir.len() - 47..] lands inside a multi-byte UTF-8 character:

thread 'main' panicked at src/cmds/system/find_cmd.rs:326:34:
start byte index 10 is not a char boundary; it is inside 'é' (bytes 9..11 of string)

Reported in #2851. Note the issue title mentions the unknown-flag path, but while preparing this fix I narrowed it down: the flag is irrelevant — the actual trigger is any grouped display of a matched directory path > 50 bytes with a multi-byte character straddling the cut point ("Les Plongées de Juliette/5-Pipeline/Versions-imprimables" is 57 bytes, so the cut lands at byte 10, inside the é). I've noted this on the issue.

Fix

Validation

🤖 Generated with Claude Code

The grouped-results display truncates directory paths longer than 50
bytes with a raw byte slice (dir.len() - 47), which panics when the cut
lands inside a multi-byte UTF-8 character (e.g. 'é' in a French path).

Extract the truncation into dir_display() and use ceil_char_boundary()
for the cut, matching the pattern already used in pipe_cmd, json_cmd
and analytics. Add regression tests.

Fixes #2851

Co-Authored-By: Claude Fable 5 <[email protected]>
@CLAassistant

CLAassistant commented Jul 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@KuSh

KuSh commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Thanks for tracking this down to the grouped directory display rather than the unknown-flag path. The find rewrite in #3603 (merged 2026-08-26) replaced that byte slice with a chars-based truncation and added a long_unicode_dir_label_does_not_panic test, so the repro from #2851 now runs clean on develop. The helper extraction here is the one piece develop does not carry, but the truncation itself is already char-safe. If you see a case that still panics, please comment and we can reopen.

@KuSh KuSh closed this Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants