Skip to content

Commit d4c1727

Browse files
Merge pull request #43 from snyk/fix/template-rendering-introduced-fields
fix: template rendering "introduced" fields
2 parents ea40287 + b51612b commit d4c1727

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

internal/presenters/funcs.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ func getVulnInfoURL(finding testapi.FindingData) string {
120120

121121
// getIntroducedThrough returns the dependency path through which the vulnerability was introduced.
122122
func getIntroducedThrough(finding testapi.FindingData) string {
123-
if len(finding.Attributes.Evidence) > 0 {
124-
evidence := finding.Attributes.Evidence[0]
123+
if finding.Attributes == nil || len(finding.Attributes.Evidence) == 0 {
124+
return ""
125+
}
125126

127+
for _, evidence := range finding.Attributes.Evidence {
126128
// An evidence object is a union type. We need to check if it's a DependencyPathEvidence.
127129
if depPathEvidence, err := evidence.AsDependencyPathEvidence(); err == nil {
128130
var pathParts []string
@@ -134,13 +136,17 @@ func getIntroducedThrough(finding testapi.FindingData) string {
134136
}
135137
}
136138
}
139+
137140
return ""
138141
}
139142

140143
// getIntroducedBy returns the direct dependency that introduced the vulnerability.
141144
func getIntroducedBy(finding testapi.FindingData) string {
142-
if len(finding.Attributes.Evidence) > 0 {
143-
evidence := finding.Attributes.Evidence[0]
145+
if finding.Attributes == nil || len(finding.Attributes.Evidence) == 0 {
146+
return ""
147+
}
148+
149+
for _, evidence := range finding.Attributes.Evidence {
144150
if depPathEvidence, err := evidence.AsDependencyPathEvidence(); err == nil {
145151
if len(depPathEvidence.Path) > 0 {
146152
// The first element in the path is the direct dependency from the root.
@@ -149,6 +155,7 @@ func getIntroducedBy(finding testapi.FindingData) string {
149155
}
150156
}
151157
}
158+
152159
return ""
153160
}
154161

0 commit comments

Comments
 (0)