Skip to content

Commit f99d155

Browse files
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>
1 parent 286c61d commit f99d155

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/markdown.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,12 @@ fn is_list_item(text: &str) -> bool {
251251
}
252252

253253
// Letter list: "a.", "a)", "(a)"
254-
if trimmed.len() >= 2 {
255-
let first = trimmed.chars().next().unwrap();
256-
let second = trimmed.chars().nth(1).unwrap();
254+
let mut chars = trimmed.chars();
255+
if let (Some(first), Some(second)) = (chars.next(), chars.next()) {
257256
if first.is_ascii_alphabetic() && (second == '.' || second == ')') {
258257
return true;
259258
}
260-
if first == '(' && trimmed.chars().nth(2) == Some(')') {
259+
if first == '(' && chars.next() == Some(')') {
261260
return true;
262261
}
263262
}

0 commit comments

Comments
 (0)