File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 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 {
324324
325325// printCodeSnippet prints the code snippet from the issue by adding a marker to the affected line
326326func 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+ }
You can’t perform that action at this time.
0 commit comments