File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -324,16 +324,38 @@ func highlight(t string, s gosec.Score) string {
324
324
325
325
// printCodeSnippet prints the code snippet from the issue by adding a marker to the affected line
326
326
func printCodeSnippet (issue * gosec.Issue ) string {
327
+ start , end := parseLine (issue .Line )
327
328
scanner := bufio .NewScanner (strings .NewReader (issue .Code ))
328
329
var buf bytes.Buffer
330
+ line := start
329
331
for scanner .Scan () {
330
332
codeLine := scanner .Text ()
331
- if strings .HasPrefix (codeLine , issue . Line ) {
333
+ if strings .HasPrefix (codeLine , strconv . Itoa ( line )) && line <= end {
332
334
codeLine = " > " + codeLine + "\n "
335
+ line ++
333
336
} else {
334
337
codeLine = " " + codeLine + "\n "
335
338
}
336
339
buf .WriteString (codeLine )
337
340
}
338
341
return buf .String ()
339
342
}
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
+ }
You can’t perform that action at this time.
0 commit comments