Repository navigation
fix(find): UTF-8-safe directory path abbreviation (char-boundary panic) - #10
Merged
Merged
Conversation
The find filter abbreviated long directory paths with a raw byte slice `&dir[dir.len() - 47..]`. When the byte offset `dir.len() - 47` lands inside a multibyte UTF-8 character (accented, CJK, emoji, etc.), Rust panics with "byte index N is not a char boundary", crashing rtk find on any legitimate path containing non-ASCII near the abbreviation boundary. Replace the byte slice with a char-boundary-safe `abbreviate_dir` helper that keeps the last 47 *characters* (via chars().rev().take(47)). For pure-ASCII paths a char is one byte, so output is byte-for-byte identical to the old behavior; multibyte paths now abbreviate by visible character instead of panicking. Adds regression tests: an emoji straddling the cut point that panicked pre-fix, 2/3/4-byte multibyte variants, ASCII-parity vs the original slice, short-multibyte verbatim, and an end-to-end run() over a real multibyte directory tree.
|
👋 Thanks for the PR! It looks like this targets Please update the base branch:
See CONTRIBUTING.md for details. |
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.
Problem
src/cmds/system/find_cmd.rsabbreviated long directory paths for display with a raw byte slice&dir[dir.len() - 47..]. When the byte offsetdir.len() - 47lands inside a multibyte UTF-8 character (accented, CJK, emoji, …), Rust panics:This crashes
rtk findon any legitimate path containing non-ASCII characters near the 50-char abbreviation boundary — flagged by the #9 filter-integrity sweep.Fix
New
abbreviate_dir(&str) -> Stringhelper that keeps the last 47 characters (chars().rev().take(47)) instead of 47 bytes:The threshold also moves from
dir.len() > 50(bytes) tochars().count() > 50(characters), which is the semantically-correct width measure and is identical for ASCII.Regression tests (fail pre-fix, pass post-fix)
abbreviate_dir_emoji_at_boundary_no_panic— a path where the cut point straddles a 4-byte emoji (panicked pre-fix).abbreviate_dir_multibyte_variants_no_panic— 2-byte (accented), 3-byte (CJK), 4-byte (emoji) paths.abbreviate_dir_ascii_unchanged— asserts byte-for-byte parity with the original&dir[dir.len()-47..]for ASCII.abbreviate_dir_short_multibyte_verbatim— short multibyte paths returned as-is.run_multibyte_path_no_panic— end-to-endrun()over a real multibyte directory tree.Proof: the first two tests FAIL with the char-boundary panic against the pre-fix code; all pass after.
Scope / second-axis check
This is the only fixed-offset byte-index slice in
find_cmd.rs. No output-mangling (entry drop/reorder): results are deterministically sorted and grouped; dir iteration order is stable via a sorted key list.glob_matchoperates on byte slices only for matching, never for display slicing.Gates
cargo fmt --check ✓ · clippy --all-targets -D unsafe_code exit 0 ✓ · cargo test --all (1746+12 pass, 0 fail) ✓ · cargo build --release ✓ · binary smoke test on emoji path exit 0 ✓