Fix panic on multi-byte UTF-8 characters in list detection

The previous code used `trimmed.len() >= 2` to check if there were at
least 2 characters, but `len()` returns byte count, not character count.
For multi-byte UTF-8 characters (e.g., "é" which is 2 bytes), this check
would pass but `chars().nth(1)` would return None, causing a panic.

Fixed by using iterator pattern matching to safely extract the first
two characters.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Abimael Martell
2026-02-06 22:20:17 -08:00
co-authored by Claude Opus 4.5
parent 286c61d128
commit f99d155c52
+3 -4
View File
@@ -251,13 +251,12 @@ fn is_list_item(text: &str) -> bool {
}
// Letter list: "a.", "a)", "(a)"
if trimmed.len() >= 2 {
let first = trimmed.chars().next().unwrap();
let second = trimmed.chars().nth(1).unwrap();
let mut chars = trimmed.chars();
if let (Some(first), Some(second)) = (chars.next(), chars.next()) {
if first.is_ascii_alphabetic() && (second == '.' || second == ')') {
return true;
}
if first == '(' && trimmed.chars().nth(2) == Some(')') {
if first == '(' && chars.next() == Some(')') {
return true;
}
}