mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-18 04:15:15 +00:00
Fix multiline secrets replacer (#700)
* Fix multiline secrets replacer * Add tests
This commit is contained in:
parent
2f780193b1
commit
366701fde7
2 changed files with 11 additions and 0 deletions
|
@ -25,6 +25,9 @@ func NewSecretsReplacer(secrets []string) *strings.Replacer {
|
||||||
}
|
}
|
||||||
// since replacer is executed on each line we have to split multi-line-secrets
|
// since replacer is executed on each line we have to split multi-line-secrets
|
||||||
for _, part := range strings.Split(old, "\n") {
|
for _, part := range strings.Split(old, "\n") {
|
||||||
|
if len(part) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
oldnew = append(oldnew, part)
|
oldnew = append(oldnew, part)
|
||||||
oldnew = append(oldnew, "********")
|
oldnew = append(oldnew, "********")
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,14 @@ func TestNewSecretsReplacer(t *testing.T) {
|
||||||
log: "start log\ndone\nnow\nan\nmulti line secret!! ;)",
|
log: "start log\ndone\nnow\nan\nmulti line secret!! ;)",
|
||||||
secrets: []string{"an\nmulti line secret!!"},
|
secrets: []string{"an\nmulti line secret!!"},
|
||||||
expect: "start log\ndone\nnow\n********\n******** ;)",
|
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 {
|
for _, c := range tc {
|
||||||
|
|
Loading…
Reference in a new issue