Skip to content

Commit

Permalink
Filter non safe runes from summary
Browse files Browse the repository at this point in the history
  • Loading branch information
janisz authored Jan 2, 2023
2 parents d95c40c + 0f42d00 commit 589da35
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os"
"strings"
"text/template"
"unicode"
)

const jql = `project in (ROX)
Expand Down Expand Up @@ -284,7 +285,11 @@ func (tc testCase) description() (string, error) {
}

func (tc testCase) summary() (string, error) {
return render(tc, summaryTpl)
s, err := render(tc, summaryTpl)
if err != nil {
return "", err
}
return clearString(s), nil
}

func render(tc testCase, text string) (string, error) {
Expand All @@ -299,3 +304,12 @@ func render(tc testCase, text string) (string, error) {
}
return tpl.String(), nil
}

func clearString(str string) string {
return strings.Map(func(r rune) rune {
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '.' || r == '/' || r == '-' || r == '_' {
return r
}
return ' '
}, str)
}
4 changes: 2 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ github.com/stackrox/rox/sensor/kubernetes/localscanner / TestLocalScannerTLSIssu
t,
[]testCase{
{
Message: `DefaultPoliciesTest / Verify policy Apache Struts: CVE-2017-5638 is triggered FAILED
Message: `DefaultPoliciesTest / Verify policy Apache Struts CVE-2017-5638 is triggered FAILED
github.com/stackrox/rox/sensor/kubernetes/localscanner / TestLocalScannerTLSIssuerIntegrationTests FAILED
github.com/stackrox/rox/sensor/kubernetes/localscanner / TestLocalScannerTLSIssuerIntegrationTests/TestSuccessfulRefresh FAILED
github.com/stackrox/rox/sensor/kubernetes/localscanner / TestLocalScannerTLSIssuerIntegrationTests/TestSuccessfulRefresh/no_secrets FAILED
Expand Down Expand Up @@ -226,5 +226,5 @@ org.spockframework.runtime.ConditionNotSatisfiedError: Condition not satisfied:
`, actual)
s, err := tc.summary()
assert.NoError(t, err)
assert.Equal(t, `DefaultPoliciesTest / Verify policy Apache Struts: CVE-2017-5638 is triggered FAILED`, s)
assert.Equal(t, `DefaultPoliciesTest / Verify policy Apache Struts CVE-2017-5638 is triggered FAILED`, s)
}

0 comments on commit 589da35

Please sign in to comment.