From 38f59653f9432230e8aaf64255e443a129f3e88f Mon Sep 17 00:00:00 2001 From: Dotan Nahum Date: Wed, 15 May 2024 11:12:38 +0300 Subject: [PATCH] fix: empty redactions, #217 --- teller-cli/tests/cmd/redact.in/.teller.yml | 11 +++++++++++ teller-cli/tests/cmd/redact.in/one.env | 3 +++ teller-cli/tests/cmd/redact.in/text.txt | 2 ++ teller-cli/tests/cmd/redact.in/two.env | 2 ++ teller-cli/tests/cmd/redact.trycmd | 4 ++++ teller-core/src/redact.rs | 17 ++++++++++------- 6 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 teller-cli/tests/cmd/redact.in/.teller.yml create mode 100644 teller-cli/tests/cmd/redact.in/one.env create mode 100644 teller-cli/tests/cmd/redact.in/text.txt create mode 100644 teller-cli/tests/cmd/redact.in/two.env create mode 100644 teller-cli/tests/cmd/redact.trycmd diff --git a/teller-cli/tests/cmd/redact.in/.teller.yml b/teller-cli/tests/cmd/redact.in/.teller.yml new file mode 100644 index 00000000..719d24a0 --- /dev/null +++ b/teller-cli/tests/cmd/redact.in/.teller.yml @@ -0,0 +1,11 @@ +providers: + dot1: + kind: dotenv + maps: + - id: one + path: one.env + dot2: + kind: dotenv + maps: + - id: two + path: two.env diff --git a/teller-cli/tests/cmd/redact.in/one.env b/teller-cli/tests/cmd/redact.in/one.env new file mode 100644 index 00000000..a52bed13 --- /dev/null +++ b/teller-cli/tests/cmd/redact.in/one.env @@ -0,0 +1,3 @@ +PRINT_NAME=linus +FOO_BAR=foo +EMPTY="" diff --git a/teller-cli/tests/cmd/redact.in/text.txt b/teller-cli/tests/cmd/redact.in/text.txt new file mode 100644 index 00000000..9a7597f4 --- /dev/null +++ b/teller-cli/tests/cmd/redact.in/text.txt @@ -0,0 +1,2 @@ +hello linus, +I just read that you made linux. diff --git a/teller-cli/tests/cmd/redact.in/two.env b/teller-cli/tests/cmd/redact.in/two.env new file mode 100644 index 00000000..18b198b4 --- /dev/null +++ b/teller-cli/tests/cmd/redact.in/two.env @@ -0,0 +1,2 @@ +PRINT_MOOD=happy +FOO_BAZ=baz diff --git a/teller-cli/tests/cmd/redact.trycmd b/teller-cli/tests/cmd/redact.trycmd new file mode 100644 index 00000000..f021b58a --- /dev/null +++ b/teller-cli/tests/cmd/redact.trycmd @@ -0,0 +1,4 @@ +```console +$ teller redact --in text.txt + +``` diff --git a/teller-core/src/redact.rs b/teller-core/src/redact.rs index d057c1f0..9d6c0871 100644 --- a/teller-core/src/redact.rs +++ b/teller-core/src/redact.rs @@ -39,13 +39,16 @@ impl Redactor { if self.has_match(message, kvs) { let mut redacted = message.to_string(); for kv in kvs { - redacted = redacted.replace( - &kv.value, - kv.meta - .as_ref() - .and_then(|m| m.redact_with.as_ref()) - .map_or("[REDACTED]", |s| s.as_str()), - ); + // only replace values with at least 2 chars + if kv.value.len() >= 2 { + redacted = redacted.replace( + &kv.value, + kv.meta + .as_ref() + .and_then(|m| m.redact_with.as_ref()) + .map_or("[REDACTED]", |s| s.as_str()), + ); + } } Cow::Owned(redacted) } else {