From 830db4673559419b89b1f7dc3acb7323474f2c4f Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Sun, 26 Jul 2026 13:38:34 -0600 Subject: [PATCH] presentation: avoid trailing separator truncation --- crates/lxmf-core/src/presentation.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/lxmf-core/src/presentation.rs b/crates/lxmf-core/src/presentation.rs index 9ec9083..126e907 100644 --- a/crates/lxmf-core/src/presentation.rs +++ b/crates/lxmf-core/src/presentation.rs @@ -28,7 +28,10 @@ pub fn sanitize_name(input: &str, max_chars: usize) -> String { continue; } if pending_space { - if retained == max_chars { + // A collapsed separator is useful only when the current visible + // character also fits. Never consume the final slot with a + // trailing space that disappears on the next sanitization pass. + if max_chars.saturating_sub(retained) < 2 { break; } output.push(' '); @@ -137,6 +140,12 @@ mod tests { assert_eq!(sanitize_name("anything", 0), ""); } + #[test] + fn truncation_never_retains_a_separator_without_following_text() { + assert_eq!(sanitize_name("¡ A", 2), "¡"); + assert_eq!(sanitize_name("A B", 3), "A B"); + } + proptest! { #[test] fn arbitrary_utf8_is_bounded_and_idempotent(input in ".*", limit in 0usize..256) {