Skip to content

Commit e77be1a

Browse files
committed
Patch csv-stream format
Updated the csv-stream format to escape double quotes in the location and filename fields, then surround each field with double quotes.
1 parent e4d1ace commit e77be1a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

processor/formatters.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"math"
1212
"os"
1313
"path/filepath"
14+
"regexp"
1415
"sort"
1516
"strconv"
1617
"strings"
@@ -467,11 +468,17 @@ func toOpenMetricsFiles(input chan *FileJob) string {
467468
func toCSVStream(input chan *FileJob) string {
468469
fmt.Println("Language,Location,Filename,Lines,Code,Comments,Blanks,Complexity,Bytes")
469470

471+
var quoteRegex = regexp.MustCompile("\"")
472+
470473
for result := range input {
474+
// Escape quotes in location and filename then surround with quotes.
475+
var location = "\"" + quoteRegex.ReplaceAllString(result.Location, "\"\"") + "\""
476+
var filename = "\"" + quoteRegex.ReplaceAllString(result.Filename, "\"\"") + "\""
477+
471478
fmt.Println(fmt.Sprintf("%s,%s,%s,%s,%s,%s,%s,%s,%s",
472479
result.Language,
473-
result.Location,
474-
result.Filename,
480+
location,
481+
filename,
475482
fmt.Sprint(result.Lines),
476483
fmt.Sprint(result.Code),
477484
fmt.Sprint(result.Comment),

0 commit comments

Comments
 (0)