Skip to content

Commit df2ff76

Browse files
committed
fix null handle
1 parent 3d468b3 commit df2ff76

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

utils/sarif.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,20 @@ func FilterRulesFromSarif(sarifData []byte) ([]byte, error) {
243243
if runMap, ok := run.(map[string]interface{}); ok {
244244
if tool, ok := runMap["tool"].(map[string]interface{}); ok {
245245
if driver, ok := tool["driver"].(map[string]interface{}); ok {
246-
driver["rules"] = nil
246+
if _, exists := driver["rules"]; exists {
247+
driver["rules"] = nil
248+
}
247249
}
248250
}
249251
}
250252
}
251253
}
252254

253255
// Marshal back to JSON with indentation
254-
return json.MarshalIndent(report, "", " ")
256+
filteredData, err := json.MarshalIndent(report, "", " ")
257+
if err != nil {
258+
return nil, fmt.Errorf("failed to marshal filtered SARIF: %w", err)
259+
}
260+
261+
return filteredData, nil
255262
}

0 commit comments

Comments
 (0)