Expand description
UTF-8-safe string truncation helpers.
Error, log, and audit paths routinely truncate user-controlled query text
for display. Slicing a &str at a fixed byte offset (&s[..100]) panics
when that offset lands inside a multi-byte UTF-8 character — a
remotely-triggerable abort if the truncated string is attacker-influenced
(audit H20). These helpers truncate on character boundaries instead.
Functions§
- truncate_
at_ char_ boundary - Borrow the longest prefix of
sthat is at mostmax_byteslong and ends on a UTF-8 character boundary. - truncate_
for_ display - Render
sfor inclusion in an error/log message, truncated tomax_bytes.