Fix #137: better handling of unicode in torrent names

This commit is contained in:
Igor Katson 2024-06-21 12:22:13 +01:00
parent 226fd0d051
commit 7147f16042
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5

View file

@ -46,15 +46,12 @@ fn debug_bytes(b: &[u8], f: &mut std::fmt::Formatter<'_>, debug_strings: bool) -
} }
match std::str::from_utf8(b) { match std::str::from_utf8(b) {
Ok(s) => { Ok(s) => {
// A test if all chars are "printable".
if s.chars().all(|c| c.escape_debug().len() == 1) {
if debug_strings { if debug_strings {
return write!(f, "{s:?}"); return write!(f, "{s:?}");
} else { } else {
return write!(f, "{s}"); return write!(f, "{s}");
} }
} }
}
Err(_e) => {} Err(_e) => {}
}; };