File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
4646fn 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'-'
You can’t perform that action at this time.
0 commit comments