Skip to content

Fix UTF-8 character handling in name truncation#116

Merged
digizeph merged 1 commit intomainfrom
fix-utf8-truncation-panic
Feb 28, 2026
Merged

Fix UTF-8 character handling in name truncation#116
digizeph merged 1 commit intomainfrom
fix-utf8-truncation-panic

Conversation

@digizeph
Copy link
Member

@digizeph digizeph commented Feb 28, 2026

Summary

Fixed panic when truncating organization names containing multi-byte UTF-8 characters (Arabic, Chinese, emoji, etc.).

Problem

The truncate_name function used byte-based string slicing (&name[..n]) which panics when the slice falls in the middle of a multi-byte UTF-8 character.

Example from issue #115:

بلو سكاي تيليكوم  (Blue Sky Telecom)

Solution

  • Changed to character-based operations: name.chars().count() and name.chars().take(n).collect()
  • Moved utils module from lens::utils to crate-level for better organization
  • Added comprehensive tests for UTF-8 handling

Changes

  • Bug fix: Fixed truncate_name in src/utils.rs to handle multi-byte characters
  • Refactoring: Moved lens/utils.rssrc/utils.rs
  • Tests: Added tests for Arabic, mixed scripts, and emoji

Testing

All tests pass:

cargo test --all-features  # 277 passed

Closes #115

Fixed panic when truncating organization names containing multi-byte UTF-8
characters (e.g., Arabic, Chinese, emoji). Changed from byte-based to
character-based string operations.

Changes:
- Fixed truncate_name to use chars().count() and chars().take() instead of
  byte-based slicing that could panic on multi-byte characters
- Moved utils module from lens::utils to crate-level utils for better
  organization (eliminates misleading structure)
- Added tests for Arabic, mixed scripts, and emoji character handling

Fixes #115
@digizeph digizeph merged commit 9b16206 into main Feb 28, 2026
1 check passed
@digizeph digizeph deleted the fix-utf8-truncation-panic branch February 28, 2026 15:05
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.

monocle crashes with panic

1 participant