mirror of
https://github.com/securego/gosec.git
synced 2024-12-24 11:35:52 +00:00
Prevent null pointer exception in Sonarqube (#334)
* fix(formatters) null value causes npe in sonarqube the json encoding of uninitialized arrays is null. this causes a npe in sonarqube tool. we should return an empty array rather than a null value here. relates to: #333
This commit is contained in:
parent
39f7e7b9e0
commit
4b59c94808
2 changed files with 11 additions and 11 deletions
|
@ -117,8 +117,8 @@ func reportSonarqube(rootPaths []string, w io.Writer, data *reportInfo) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func convertToSonarIssues(rootPaths []string, data *reportInfo) (sonarIssues, error) {
|
||||
var si sonarIssues
|
||||
func convertToSonarIssues(rootPaths []string, data *reportInfo) (*sonarIssues, error) {
|
||||
si := &sonarIssues{[]sonarIssue{}}
|
||||
for _, issue := range data.Issues {
|
||||
var sonarFilePath string
|
||||
for _, rootPath := range rootPaths {
|
||||
|
|
|
@ -32,7 +32,7 @@ var _ = Describe("Formatter", func() {
|
|||
NumFound: 0,
|
||||
},
|
||||
}
|
||||
want := sonarIssues{
|
||||
want := &sonarIssues{
|
||||
SonarIssues: []sonarIssue{
|
||||
{
|
||||
EngineID: "gosec",
|
||||
|
@ -56,7 +56,7 @@ var _ = Describe("Formatter", func() {
|
|||
|
||||
issues, err := convertToSonarIssues([]string{rootPath}, data)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
Expect(issues).To(Equal(want))
|
||||
Expect(*issues).To(Equal(*want))
|
||||
})
|
||||
|
||||
It("it should parse the report info with files in subfolders", func() {
|
||||
|
@ -80,7 +80,7 @@ var _ = Describe("Formatter", func() {
|
|||
NumFound: 0,
|
||||
},
|
||||
}
|
||||
want := sonarIssues{
|
||||
want := &sonarIssues{
|
||||
SonarIssues: []sonarIssue{
|
||||
{
|
||||
EngineID: "gosec",
|
||||
|
@ -104,7 +104,7 @@ var _ = Describe("Formatter", func() {
|
|||
|
||||
issues, err := convertToSonarIssues([]string{rootPath}, data)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
Expect(issues).To(Equal(want))
|
||||
Expect(*issues).To(Equal(*want))
|
||||
})
|
||||
It("it should not parse the report info for files from other projects", func() {
|
||||
data := &reportInfo{
|
||||
|
@ -127,15 +127,15 @@ var _ = Describe("Formatter", func() {
|
|||
NumFound: 0,
|
||||
},
|
||||
}
|
||||
want := sonarIssues{
|
||||
SonarIssues: nil,
|
||||
want := &sonarIssues{
|
||||
SonarIssues: []sonarIssue{},
|
||||
}
|
||||
|
||||
rootPath := "/home/src/project2"
|
||||
|
||||
issues, err := convertToSonarIssues([]string{rootPath}, data)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
Expect(issues).To(Equal(want))
|
||||
Expect(*issues).To(Equal(*want))
|
||||
})
|
||||
|
||||
It("it should parse the report info for multiple projects projects", func() {
|
||||
|
@ -168,7 +168,7 @@ var _ = Describe("Formatter", func() {
|
|||
NumFound: 0,
|
||||
},
|
||||
}
|
||||
want := sonarIssues{
|
||||
want := &sonarIssues{
|
||||
SonarIssues: []sonarIssue{
|
||||
{
|
||||
EngineID: "gosec",
|
||||
|
@ -207,7 +207,7 @@ var _ = Describe("Formatter", func() {
|
|||
|
||||
issues, err := convertToSonarIssues(rootPaths, data)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
Expect(issues).To(Equal(want))
|
||||
Expect(*issues).To(Equal(*want))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue