From 411118b550957ce8134e720ce329fd1cdbbcd344 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sun, 14 Nov 2021 11:17:54 +0100 Subject: [PATCH] fix(core): fix string clipping operator that crashed with some unicode chars --- .../cli/worker/engine/process/middleware/match_select.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/espanso/src/cli/worker/engine/process/middleware/match_select.rs b/espanso/src/cli/worker/engine/process/middleware/match_select.rs index b318bc2..0f0b74e 100644 --- a/espanso/src/cli/worker/engine/process/middleware/match_select.rs +++ b/espanso/src/cli/worker/engine/process/middleware/match_select.rs @@ -55,11 +55,15 @@ impl<'a> MatchSelector for MatchSelectorAdapter<'a> { let search_items: Vec = matches .into_iter() .map(|m| { - let clipped_label = &m.label[..std::cmp::min(m.label.len(), MAX_LABEL_LEN)]; + let clipped_label: String = m + .label + .chars() + .take(std::cmp::min(m.label.len(), MAX_LABEL_LEN)) + .collect(); SearchItem { id: m.id.to_string(), - label: clipped_label.to_string(), + label: clipped_label, tag: m.tag.map(String::from), is_builtin: m.is_builtin, }