Skip to content

Commit

Permalink
Patch csv-stream format
Browse files Browse the repository at this point in the history
Updated the csv-stream format to escape double quotes in the location and filename fields, then surround each field with double quotes.
  • Loading branch information
dbyrne-xfr committed Jan 27, 2023
1 parent e4d1ace commit e77be1a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"math"
"os"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -467,11 +468,17 @@ func toOpenMetricsFiles(input chan *FileJob) string {
func toCSVStream(input chan *FileJob) string {
fmt.Println("Language,Location,Filename,Lines,Code,Comments,Blanks,Complexity,Bytes")

var quoteRegex = regexp.MustCompile("\"")

for result := range input {
// Escape quotes in location and filename then surround with quotes.
var location = "\"" + quoteRegex.ReplaceAllString(result.Location, "\"\"") + "\""
var filename = "\"" + quoteRegex.ReplaceAllString(result.Filename, "\"\"") + "\""

fmt.Println(fmt.Sprintf("%s,%s,%s,%s,%s,%s,%s,%s,%s",
result.Language,
result.Location,
result.Filename,
location,
filename,
fmt.Sprint(result.Lines),
fmt.Sprint(result.Code),
fmt.Sprint(result.Comment),
Expand Down

0 comments on commit e77be1a

Please sign in to comment.