aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared
diff options
context:
space:
mode:
authorLibravatar D.Loh <lploh2016@gmail.com>2020-02-06 20:30:58 -0800
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-02-07 20:29:58 +0100
commit6a63520785e65d8bfe9fd9e4f1db39d7ffab045d (patch)
treee28240d90bde22cbb2eac47a175fec02dd3f8bc1 /askama_shared
parentf334e07b9e9f435a279ace92d56855c63ec1ad4e (diff)
downloadaskama-6a63520785e65d8bfe9fd9e4f1db39d7ffab045d.tar.gz
askama-6a63520785e65d8bfe9fd9e4f1db39d7ffab045d.tar.bz2
askama-6a63520785e65d8bfe9fd9e4f1db39d7ffab045d.zip
eliminate panic on len not lie on boundary
check boundary, add truncate len per 1 as needed till checking pass
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)
}