launcher: avoid UTF-8 char-boundary panic in replace_ignore_case #35
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/35"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from edsuuu/VI-BR-PORT. Originally posted by ahmetbagci8 on 2026-11-29T12:35:32Z.
Problem
In pps/vi-launcher/src/ui.rs,
eplace_ignore_case checked lower.len() != text.len() and assumed equal total byte lengths meant byte offsets in ext.to_lowercase() aligned 1:1 with UTF-8 char boundaries in ext.
When ext contains Unicode characters whose lowercase byte-length changes cancel out (for example two 'İ' U+0130 2 -> 3 bytes and one 'K' U+212A 3 -> 1 bytes), lower.len() == text.len() still holds, but lower[at..].find(&needle) returns a byte offset that lands inside a multi-byte character of ext, panicking at &text[at..at + i]. It also fell back to case-sensitive ext.replace whenever ext contained any length-changing character like 'İ'.
Fix
Build lower char-by-char alongside a byte-offset map back to original UTF-8 char boundaries in ext, and slice ext only at mapped boundaries. Added unit test
eplace_ignore_case_handles_unicode_case_length_changes.
Verification
Imported from edsuuu/VI-BR-PORT. Originally posted by edsuuu on 2026-11-29T13:07:09Z.
Code review location:
apps/vi-launcher/src/ui.rs; line 2021The comment can name them by code point, e.g.
U+0130 (2B -> 3B) x2 (+2B) + U+212A Kelvin sign (3B -> 1B).Imported from edsuuu/VI-BR-PORT. Originally posted by edsuuu on 2026-11-29T13:07:09Z.
Code review location:
apps/vi-launcher/src/ui.rs; line 2023"\u{130}\u{130}a\u{212A}"and"\u{130}\u{130}X\u{212A}"keep the same bytes.Imported from edsuuu/VI-BR-PORT. Originally posted by edsuuu on 2026-11-29T13:07:09Z.
Code review location:
apps/vi-launcher/src/ui.rs; line 2024"C:\\Users\\\u{130}smail\\Log"likewise.Imported from edsuuu/VI-BR-PORT. Originally posted by edsuuu on 2026-11-29T13:07:09Z.
Review: CHANGES_REQUESTED
Thanks, the fix is right and the test covers the case well. One thing stops the CI: the repository rule
cargo test -p xtask(xtask/src/english.rs) allows only ASCII letters in comments and literals. Could you write the non-ASCII characters as escapes? The bytes stay the same.Imported from edsuuu/VI-BR-PORT. Originally posted by ahmetbagci8 on 2026-11-29T13:25:08Z.
Updated the test comments and literals to use \\u{0130}\ / \\u{212A}\ escapes and verified \cargo test -p xtask\ (34 passed, 0 failed) along with \cargo test -p vi-launcher mask_tests\ and \cargo clippy -p vi-launcher --tests.