diff --git a/apps/figcraft-server/src/store.rs b/apps/figcraft-server/src/store.rs index a60d482d..ab65c2d8 100644 --- a/apps/figcraft-server/src/store.rs +++ b/apps/figcraft-server/src/store.rs @@ -296,7 +296,8 @@ fn clean_name(s: &str) -> String { /// A report's reason: trimmed, control and bidi characters turned into spaces, at most `MAX_REASON` characters. fn clean_reason(s: &str) -> String { - s.trim().chars().map(|c| if c.is_control() || is_bidi_control(c) { ' ' } else { c }).take(MAX_REASON).collect() + let s: String = s.chars().map(|c| if c.is_control() || is_bidi_control(c) { ' ' } else { c }).collect(); + s.trim().chars().take(MAX_REASON).collect() } /// Bidirectional format characters, which could reorder what a terminal shows. diff --git a/apps/figcraft-server/src/store_tests.rs b/apps/figcraft-server/src/store_tests.rs index bd1d9c32..d8c5b915 100644 --- a/apps/figcraft-server/src/store_tests.rs +++ b/apps/figcraft-server/src/store_tests.rs @@ -391,6 +391,11 @@ fn names_and_report_reasons_lose_bidi_controls() { assert_eq!(store.reports().last().unwrap().reason, "a b", "reason U+{:04X}", m as u32); store.remove(&id).unwrap(); } + // A reason that is only control characters says nothing. + let (id, _, _) = publish(&mut store, "blank"); + for blank in ["\0", "\u{202E}", " \0\t\u{2066} "] { + assert!(store.keep_report(&id, None, "192.0.2.99".parse().unwrap(), blank).is_err(), "{blank:?}"); + } } #[test]