Skip to content

Commit 304e22a

Browse files
Zxillyldez
andauthored
fix: sanitize level property for SARIF (#4831)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent 9211eec commit 304e22a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pkg/printers/sarif.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ func (p Sarif) Print(issues []result.Issue) error {
7676
issue := issues[i]
7777

7878
severity := issue.Severity
79-
if severity == "" {
79+
80+
switch severity {
81+
// https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790898
82+
case "none", "note", "warning", "error":
83+
// Valid levels.
84+
default:
8085
severity = "error"
8186
}
8287

pkg/printers/sarif_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestSarif_Print(t *testing.T) {
4242
},
4343
{
4444
FromLinter: "linter-a",
45-
Severity: "error",
45+
Severity: "low",
4646
Text: "some issue 2",
4747
Pos: token.Position{
4848
Filename: "path/to/filec.go",

0 commit comments

Comments
 (0)