Skip to content

Commit 98aba42

Browse files
committed
fix(temporal): handle multi-byte UTF-8 filenames in date extraction
1 parent 989c511 commit 98aba42

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/temporal.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ fn extract_date_from_frontmatter(frontmatter: &str) -> Option<i64> {
4444

4545
/// Extract YYYY-MM-DD pattern from a filename.
4646
fn extract_date_from_filename(filename: &str) -> Option<i64> {
47-
// Look for YYYY-MM-DD pattern anywhere in the filename
47+
// Look for YYYY-MM-DD pattern anywhere in the filename.
48+
// Only check ASCII char boundaries to avoid panics on multi-byte UTF-8 filenames.
4849
let bytes = filename.as_bytes();
4950
if bytes.len() < 10 {
5051
return None;
5152
}
5253
for i in 0..=bytes.len() - 10 {
54+
// Skip non-ASCII-start positions to avoid slicing mid-character
55+
if !filename.is_char_boundary(i) || !filename.is_char_boundary(i + 10) {
56+
continue;
57+
}
5358
let candidate = &filename[i..i + 10];
5459
if candidate.as_bytes()[4] == b'-'
5560
&& candidate.as_bytes()[7] == b'-'

0 commit comments

Comments
 (0)