Skip to content

Commit

Permalink
fix: empty redactions, #217
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed May 15, 2024
1 parent 5d0d60a commit 38f5965
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
11 changes: 11 additions & 0 deletions teller-cli/tests/cmd/redact.in/.teller.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
providers:
dot1:
kind: dotenv
maps:
- id: one
path: one.env
dot2:
kind: dotenv
maps:
- id: two
path: two.env
3 changes: 3 additions & 0 deletions teller-cli/tests/cmd/redact.in/one.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PRINT_NAME=linus
FOO_BAR=foo
EMPTY=""
2 changes: 2 additions & 0 deletions teller-cli/tests/cmd/redact.in/text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hello linus,
I just read that you made linux.
2 changes: 2 additions & 0 deletions teller-cli/tests/cmd/redact.in/two.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PRINT_MOOD=happy
FOO_BAZ=baz
4 changes: 4 additions & 0 deletions teller-cli/tests/cmd/redact.trycmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```console
$ teller redact --in text.txt

```
17 changes: 10 additions & 7 deletions teller-core/src/redact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 38f5965

Please sign in to comment.