Bug Description
When user input contains special characters or emoji, Forge Code panics with:
ERROR: byte index 3 is not a char boundary; it is inside '✅' (bytes 1..4) of `'✅`
This is a Rust string slicing bug where &str[..n] is used with a byte index that falls in the middle of a multi-byte UTF-8 character.
Steps to Reproduce
- Send a message to Forge Code that contains emoji or special characters, for example:
- Forge Code panics with a
byte index N is not a char boundary error.
Expected Behavior
Forge Code should correctly handle any valid UTF-8 input, including emoji (4 bytes each), special symbols, and other multi-byte characters without panicking.
Root Cause
Somewhere in the Rust codebase, a string is being sliced using byte indices (e.g., &text[..n] or &text[start..end]) without verifying that the indices fall on character boundaries. Emoji are 4 bytes each in UTF-8, many special symbols are 2-3 bytes — so any naive byte-level truncation/slicing will panic for non-ASCII input.
Suggested Fix
Replace raw byte-index slicing with one of the following approaches:
-
Use str::is_char_boundary() to validate indices before slicing:
if text.is_char_boundary(n) {
&text[..n]
} else {
&text[..text.floor_char_boundary(n)] // nightly, or manual fallback
}
-
Use char_indices() to find the correct byte offset for a given character position:
let byte_idx = text.char_indices().nth(char_limit).map(|(i, _)| i).unwrap_or(text.len());
&text[..byte_idx]
-
Use .chars().take(n).collect::<String>() if a character-count limit is intended.
Environment
- macOS
- Forge Code CLI
- Trigger: emoji and special characters in user input
Bug Description
When user input contains special characters or emoji, Forge Code panics with:
This is a Rust string slicing bug where
&str[..n]is used with a byte index that falls in the middle of a multi-byte UTF-8 character.Steps to Reproduce
✅ deploy the appbyte index N is not a char boundaryerror.Expected Behavior
Forge Code should correctly handle any valid UTF-8 input, including emoji (4 bytes each), special symbols, and other multi-byte characters without panicking.
Root Cause
Somewhere in the Rust codebase, a string is being sliced using byte indices (e.g.,
&text[..n]or&text[start..end]) without verifying that the indices fall on character boundaries. Emoji are 4 bytes each in UTF-8, many special symbols are 2-3 bytes — so any naive byte-level truncation/slicing will panic for non-ASCII input.Suggested Fix
Replace raw byte-index slicing with one of the following approaches:
Use
str::is_char_boundary()to validate indices before slicing:Use
char_indices()to find the correct byte offset for a given character position:Use
.chars().take(n).collect::<String>()if a character-count limit is intended.Environment