From 366701fde727cb7a9e7f21eb88264f59f6f9b89c Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 16 Jan 2022 22:57:37 +0100 Subject: [PATCH] Fix multiline secrets replacer (#700) * Fix multiline secrets replacer * Add tests --- pipeline/shared/replace_secrets.go | 3 +++ pipeline/shared/replace_secrets_test.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/pipeline/shared/replace_secrets.go b/pipeline/shared/replace_secrets.go index ad0899103..6e57f817f 100644 --- a/pipeline/shared/replace_secrets.go +++ b/pipeline/shared/replace_secrets.go @@ -25,6 +25,9 @@ func NewSecretsReplacer(secrets []string) *strings.Replacer { } // since replacer is executed on each line we have to split multi-line-secrets for _, part := range strings.Split(old, "\n") { + if len(part) == 0 { + continue + } oldnew = append(oldnew, part) oldnew = append(oldnew, "********") } diff --git a/pipeline/shared/replace_secrets_test.go b/pipeline/shared/replace_secrets_test.go index f5a26a140..962ba3378 100644 --- a/pipeline/shared/replace_secrets_test.go +++ b/pipeline/shared/replace_secrets_test.go @@ -23,6 +23,14 @@ func TestNewSecretsReplacer(t *testing.T) { log: "start log\ndone\nnow\nan\nmulti line secret!! ;)", secrets: []string{"an\nmulti line secret!!"}, expect: "start log\ndone\nnow\n********\n******** ;)", + }, { + log: "start log\ndone\nnow\nan\nmulti line secret!! ;)", + secrets: []string{"Test\nwith\n\ntwo new lines"}, + expect: "start log\ndone\nnow\nan\nmulti line secret!! ;)", + }, { + log: "start log\ndone\nnow\nan\nmulti line secret!! ;)\nwith\ntwo\n\nnewlines", + secrets: []string{"an\nmulti line secret!!", "two\n\nnewlines"}, + expect: "start log\ndone\nnow\n********\n******** ;)\nwith\n********\n\n********", }} for _, c := range tc {