From af99a6ecb4723d0ea03982797a1becd8437d3f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Bene=C5=A1?= Date: Sun, 28 Jul 2024 13:42:38 +0200 Subject: [PATCH] impl: fix discrepancy in upper/lower case in `impl fmt::Debug for BStr` Make all of the debug output in lower-case. Closes #188, Closes #189 --- src/impls.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/impls.rs b/src/impls.rs index 4abc8b5..ca20722 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -487,7 +487,7 @@ mod bstr { write!(f, "{}", ch.escape_debug())?; } else { for &b in self[s..e].as_bytes() { - write!(f, r"\x{:02X}", b)?; + write!(f, "\\x{:02x}", b)?; } } } @@ -1245,11 +1245,19 @@ fn test_debug() { // replacement codepoint, then we emit the codepoint just like other // non-printable Unicode characters. assert_eq!( - b"\"\\xFF\xEF\xBF\xBD\\xFF\"".as_bstr(), + b"\"\\xff\xef\xbf\xbd\\xff\"".as_bstr(), // Before fixing #72, the output here would be: // \\xFF\\xEF\\xBF\\xBD\\xFF - B(&format!("{:?}", b"\xFF\xEF\xBF\xBD\xFF".as_bstr())).as_bstr(), + B(&format!("{:?}", b"\xff\xef\xbf\xbd\xff".as_bstr())).as_bstr(), ); + + // Tests that all ASCII control characters are in lower case. + assert_eq!( + b"\"\\xed\\xa0\\x80Aa\\x7f\\x0b\"".as_bstr(), + // Before fixing #188, the output here would be: + // \\xED\\xA0\\x80Aa\\x7f\\x0b + B(&format!("{:?}", b"\xed\xa0\x80Aa\x7f\x0b".as_bstr())).as_bstr(), + ) } // See: https://github.com/BurntSushi/bstr/issues/82