From 3a9a6ad8b39ede23b6f10ef6f49a34b678abcd7f Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Thu, 13 May 2021 16:02:28 +0200 Subject: [PATCH] Sarif provide Snippet with Issue.Code * Provide Snippet with Issue.Code * Fix documentation --- report/sarif/builder.go | 13 +++++++++++++ report/sarif/formatter.go | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/report/sarif/builder.go b/report/sarif/builder.go index bef7433..06ac6c8 100644 --- a/report/sarif/builder.go +++ b/report/sarif/builder.go @@ -58,6 +58,19 @@ func NewRegion(startLine int, endLine int, startColumn int, endColumn int, sourc } } +//WithSnippet defines the Snippet for the current Region +func (r *Region) WithSnippet(snippet *ArtifactContent) *Region { + r.Snippet = snippet + return r +} + +//NewArtifactContent instantiate an ArtifactContent +func NewArtifactContent(text string) *ArtifactContent { + return &ArtifactContent{ + Text: text, + } +} + //NewTool instantiate a Tool func NewTool(driver *ToolComponent) *Tool { return &Tool{ diff --git a/report/sarif/formatter.go b/report/sarif/formatter.go index cbdc3e1..6e4464a 100644 --- a/report/sarif/formatter.go +++ b/report/sarif/formatter.go @@ -172,12 +172,12 @@ func parseSarifRegion(issue *gosec.Issue) (*Region, error) { return nil, err } } - col, err := strconv.Atoi(issue.Col) if err != nil { return nil, err } - return NewRegion(startLine, endLine, col, col, "go"), nil + snippet := NewArtifactContent(issue.Code) + return NewRegion(startLine, endLine, col, col, "go").WithSnippet(snippet), nil } func getSarifLevel(s string) Level {