Skip to content

Commit

Permalink
bugfix:364 fix sarif parser bug where if no endline was provided the …
Browse files Browse the repository at this point in the history
…output would end in '-'
  • Loading branch information
northdpole committed Sep 19, 2024
1 parent 182d85f commit a48625a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/sarif/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ func parseOut(run sarif.Run, rules map[string]*sarif.ReportingDescriptor, toolNa
}
if loc.PhysicalLocation.Region.EndLine != nil {
el = fmt.Sprintf("%d", *loc.PhysicalLocation.Region.EndLine)
} else {
el = sl
}
target = fmt.Sprintf("%s:%s-%s", uri, sl, el)
} else {
Expand Down
8 changes: 8 additions & 0 deletions pkg/sarif/sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ func Test_ParseOut(t *testing.T) {
}

expectedIssues := []*v1.Issue{
{
Target: "main.go:83-83",
Type: "G404",
Title: "[test for missing endLine, common in some tools]",
Severity: v1.Severity_SEVERITY_HIGH,
Confidence: v1.Confidence_CONFIDENCE_UNSPECIFIED,
Description: "Message: [test for missing endLine, common in some tools]",
},
{
Target: "main.go:83-83",
Type: "G404",
Expand Down
27 changes: 25 additions & 2 deletions pkg/sarif/testdata/example_output.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
{
"runs": [{
"results": [{
"results": [
{
"level": "error",
"locations": [{
"physicalLocation": {
"artifactLocation": {
"uri": "main.go"
},
"region": {
"snippet": {
"text": "r := rand.New(rand.NewSource(time.Now().UnixNano()))"
},
"sourceLanguage": "go",
"startColumn": 7,
"startLine": 83
}
}
}],
"message": {
"text": "[test for missing endLine, common in some tools]"
},
"ruleId": "G404"
},
{
"level": "error",
"locations": [{
"physicalLocation": {
Expand Down Expand Up @@ -60,4 +83,4 @@
}],
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0"
}
}

0 comments on commit a48625a

Please sign in to comment.