From 6dfa2df06ff20302dd288e4a020238680077ba38 Mon Sep 17 00:00:00 2001 From: baishen Date: Wed, 16 Oct 2024 10:31:40 +0800 Subject: [PATCH] fix OwnedBytes debug panic (#2512) --- ownedbytes/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ownedbytes/src/lib.rs b/ownedbytes/src/lib.rs index 9266af386..111ad4444 100644 --- a/ownedbytes/src/lib.rs +++ b/ownedbytes/src/lib.rs @@ -151,7 +151,7 @@ impl fmt::Debug for OwnedBytes { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // We truncate the bytes in order to make sure the debug string // is not too long. - let bytes_truncated: &[u8] = if self.len() > 8 { + let bytes_truncated: &[u8] = if self.len() > 10 { &self.as_slice()[..10] } else { self.as_slice() @@ -252,6 +252,11 @@ mod tests { format!("{short_bytes:?}"), "OwnedBytes([97, 98, 99, 100], len=4)" ); + let medium_bytes = OwnedBytes::new(b"abcdefghi".as_ref()); + assert_eq!( + format!("{medium_bytes:?}"), + "OwnedBytes([97, 98, 99, 100, 101, 102, 103, 104, 105], len=9)" + ); let long_bytes = OwnedBytes::new(b"abcdefghijklmnopq".as_ref()); assert_eq!( format!("{long_bytes:?}"),