Skip to content

Commit

Permalink
impl: fix discrepancy in upper/lower case in impl fmt::Debug for BStr
Browse files Browse the repository at this point in the history
Make all of the debug output in lower-case.

Closes #188, Closes #189
  • Loading branch information
wbenny authored and BurntSushi committed Nov 13, 2024
1 parent 955fa16 commit af99a6e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit af99a6e

Please sign in to comment.