File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import (
20
20
"bytes"
21
21
"encoding/json"
22
22
"fmt"
23
+ "io"
23
24
"text/template"
24
25
25
26
"github.com/arduino/arduino-lint/internal/configuration"
@@ -222,12 +223,18 @@ func (results Type) JSONReport() string {
222
223
223
224
// jsonReportRaw returns the report marshalled into JSON format in byte encoding.
224
225
func (results Type ) jsonReportRaw () []byte {
225
- reportJSON , err := json .MarshalIndent (results , "" , " " )
226
+ var marshalledReportBuffer bytes.Buffer
227
+ jsonEncoder := json .NewEncoder (io .Writer (& marshalledReportBuffer ))
228
+ // By default, the json package HTML-sanitizes strings during marshalling (https://golang.org/pkg/encoding/json/#Marshal)
229
+ // This means that the simple json.MarshalIndent() approach would result in the report containing gibberish.
230
+ jsonEncoder .SetEscapeHTML (false )
231
+ jsonEncoder .SetIndent ("" , " " )
232
+ err := jsonEncoder .Encode (results )
226
233
if err != nil {
227
234
panic (fmt .Sprintf ("Error while formatting rules report: %v" , err ))
228
235
}
229
236
230
- return reportJSON
237
+ return marshalledReportBuffer . Bytes ()
231
238
}
232
239
233
240
// WriteReport writes a report for all projects to the specified file.
You can’t perform that action at this time.
0 commit comments