Commit f0084e3f authored by Nick Mathewson's avatar Nick Mathewson 🦀
Browse files

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.
parent 30140cb0
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -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");
    }
}