Skip to content

Commit 6bcd89a

Browse files
ccojocarCosmin Cojocar
authored and
Cosmin Cojocar
committed
Mark all lines of a multi-line finding
Signed-off-by: Cosmin Cojocar <[email protected]>
1 parent 4d4e594 commit 6bcd89a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

output/formatter.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,38 @@ func highlight(t string, s gosec.Score) string {
324324

325325
// printCodeSnippet prints the code snippet from the issue by adding a marker to the affected line
326326
func printCodeSnippet(issue *gosec.Issue) string {
327+
start, end := parseLine(issue.Line)
327328
scanner := bufio.NewScanner(strings.NewReader(issue.Code))
328329
var buf bytes.Buffer
330+
line := start
329331
for scanner.Scan() {
330332
codeLine := scanner.Text()
331-
if strings.HasPrefix(codeLine, issue.Line) {
333+
if strings.HasPrefix(codeLine, strconv.Itoa(line)) && line <= end {
332334
codeLine = " > " + codeLine + "\n"
335+
line++
333336
} else {
334337
codeLine = " " + codeLine + "\n"
335338
}
336339
buf.WriteString(codeLine)
337340
}
338341
return buf.String()
339342
}
343+
344+
// parseLine extract the start and the end line numbers from a issue line
345+
func parseLine(line string) (int, int) {
346+
parts := strings.Split(line, "-")
347+
start := parts[0]
348+
end := start
349+
if len(parts) > 1 {
350+
end = parts[1]
351+
}
352+
s, err := strconv.Atoi(start)
353+
if err != nil {
354+
return -1, -1
355+
}
356+
e, err := strconv.Atoi(end)
357+
if err != nil {
358+
return -1, -1
359+
}
360+
return s, e
361+
}

0 commit comments

Comments
 (0)