aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared
diff options
context:
space:
mode:
Diffstat (limited to 'askama_shared')
-rw-r--r--askama_shared/src/filters/mod.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/askama_shared/src/filters/mod.rs b/askama_shared/src/filters/mod.rs
index f5d2720..11216a5 100644
--- a/askama_shared/src/filters/mod.rs
+++ b/askama_shared/src/filters/mod.rs
@@ -161,7 +161,11 @@ pub fn truncate(s: &dyn fmt::Display, len: &usize) -> Result<String> {
if s.len() < *len {
Ok(s)
} else {
- s.truncate(*len);
+ let mut real_len = *len;
+ while !s.is_char_boundary(real_len) {
+ real_len += 1;
+ }
+ s.truncate(real_len);
s.push_str("...");
Ok(s)
}