Skip to content

Commit

Permalink
Merge pull request #282 from luotianqi777/fix_csv
Browse files Browse the repository at this point in the history
fix: csv report
  • Loading branch information
luotianqi777 authored Feb 22, 2024
2 parents 378b707 + 7b8797c commit 4385230
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cmd/format/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package format
import (
"fmt"
"io"
"strings"

"github.com/xmirrorsecurity/opensca-cli/v3/cmd/detail"
)
Expand All @@ -18,8 +19,25 @@ func Csv(report Report, out string) {
licenseTxt = n.Licenses[0].ShortName
}

formatCsv := func(s string) string {
if strings.Contains(s, `"`) {
s = strings.ReplaceAll(s, `"`, `""`)
}
if strings.Contains(s, `,`) {
s = fmt.Sprintf(`"%s"`, s)
}
return s
}

if n.Name != "" {
table = table + fmt.Sprintf("%s,%s,%s,%s,%s,%s\n", n.Name, n.Version, n.Vendor, licenseTxt, n.Language, n.Purl())
table = table + fmt.Sprintf("%s,%s,%s,%s,%s,%s\n",
formatCsv(n.Name),
formatCsv(n.Version),
formatCsv(n.Vendor),
formatCsv(licenseTxt),
formatCsv(n.Language),
formatCsv(n.Purl()),
)
}

return true
Expand Down

0 comments on commit 4385230

Please sign in to comment.