Fix a logic error in Redacted.

Previously it was redacting exactly when safelogging was _disabled_,
which obviously isn't correct.

Fixes #671. Regression test included.
This commit is contained in:
Nick Mathewson 2022-11-30 09:07:33 -05:00
parent 30140cb07b
commit f0084e3fd4
1 changed files with 13 additions and 4 deletions

View File

@ -267,9 +267,9 @@ impl<T: Redactable> Redacted<T> {
impl<T: Redactable> std::fmt::Display for Redacted<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if flags::unsafe_logging_enabled() {
self.0.display_redacted(f)
} else {
std::fmt::Display::fmt(&self.0, f)
} else {
self.0.display_redacted(f)
}
}
}
@ -277,9 +277,9 @@ impl<T: Redactable> std::fmt::Display for Redacted<T> {
impl<T: Redactable> std::fmt::Debug for Redacted<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if flags::unsafe_logging_enabled() {
self.0.debug_redacted(f)
} else {
std::fmt::Debug::fmt(&self.0, f)
} else {
self.0.debug_redacted(f)
}
}
}
@ -385,4 +385,13 @@ mod test {
assert_eq!(s1, "[scrubbed], [scrubbed]");
assert_eq!(s2, expect);
}
#[test]
fn test_redacted() {
let localhost = std::net::Ipv4Addr::LOCALHOST;
let closure = || format!("{}", localhost.redacted());
assert_eq!(closure(), "127.x.x.x");
assert_eq!(with_safe_logging_suppressed(closure), "127.0.0.1");
}
}