Batch r2-1 review: a report reason blank after cleaning is refused

This commit is contained in:
bflatastic
2026-10-24 10:31:22 +07:00
parent d114c6ed92
commit c45c693278
2 changed files with 7 additions and 1 deletions
+2 -1
View File
@@ -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.
+5
View File
@@ -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]