File tree Expand file tree Collapse file tree
packages/desktop/src-tauri/src/commands Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -366,15 +366,41 @@ fn extract_description(raw: &str) -> Option<String> {
366366 }
367367
368368 let max = 180 ;
369- if cleaned. len ( ) > max {
370- return Some ( format ! ( "{}..." , & cleaned[ ..max] ) ) ;
369+ let truncated: String = cleaned. chars ( ) . take ( max) . collect ( ) ;
370+ if truncated. len ( ) < cleaned. len ( ) {
371+ return Some ( format ! ( "{}..." , truncated) ) ;
371372 }
372373 return Some ( cleaned) ;
373374 }
374375
375376 None
376377}
377378
379+ #[ cfg( test) ]
380+ mod tests {
381+ use super :: extract_description;
382+
383+ #[ test]
384+ fn extract_description_truncates_multibyte_text_without_panicking ( ) {
385+ let raw = & "て" . repeat ( 181 ) ;
386+
387+ let description = extract_description ( raw) . expect ( "description should be present" ) ;
388+
389+ assert ! ( description. ends_with( "..." ) ) ;
390+ assert ! ( description. is_char_boundary( description. len( ) ) ) ;
391+ assert_eq ! ( description. chars( ) . count( ) , 183 ) ;
392+ }
393+
394+ #[ test]
395+ fn extract_description_keeps_short_text_unchanged ( ) {
396+ let raw = "Short description" ;
397+
398+ let description = extract_description ( raw) . expect ( "description should be present" ) ;
399+
400+ assert_eq ! ( description, "Short description" ) ;
401+ }
402+ }
403+
378404#[ tauri:: command]
379405pub fn list_local_skills ( project_dir : String ) -> Result < Vec < LocalSkillCard > , String > {
380406 let project_dir = project_dir. trim ( ) ;
You can’t perform that action at this time.
0 commit comments