From: Ian Jackson Date: Tue, 17 May 2022 00:58:26 +0000 (+0100) Subject: Html: Fix Debug truncation to not randomly panic X-Git-Tag: otter-1.1.0~76 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=2bfdb8a3c1cce30dd230435f25df83bd9587bb8a;p=otter.git Html: Fix Debug truncation to not randomly panic Ow! Signed-off-by: Ian Jackson --- diff --git a/base/html.rs b/base/html.rs index 85a8f521..bf540dbc 100644 --- a/base/html.rs +++ b/base/html.rs @@ -14,7 +14,9 @@ impl Debug for HtmlStr { if self.len() < MAX { write!(f, "<{}>", &self.0) } else { - write!(f, "<{}>...", &self.0[0..MAX-3]) + let lim = (MAX-3 ..).into_iter() + .find(|&i| self.0.is_char_boundary(i)).unwrap(); + write!(f, "<{}>...", &self.0[0..lim]) } } }