Skip to content

Commit

Permalink
Fix panicking string index
Browse files Browse the repository at this point in the history
  • Loading branch information
augustuswm committed Feb 2, 2024
1 parent 495f269 commit 238e500
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rfd-cli/src/printer/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,13 @@ impl TabDisplay for SearchResultHit {
}

printer.print_field(tw, level, "location", &heading_path.iter().join(" > "));
printer.print_field(tw, level, "content", &&self.content[..255]);

fn get_slice_of_string(s: &str, n: usize) -> &str {
let char_boundary = s.char_indices().nth(n).map_or(s.len(), |(idx, _)| idx);
&s[..char_boundary]
}

printer.print_field(tw, level, "content", &format!("{}...", get_slice_of_string(&self.content, 255)));
}
}

Expand Down

0 comments on commit 238e500

Please sign in to comment.