File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import (
2020 "bytes"
2121 "encoding/json"
2222 "fmt"
23+ "io"
2324 "text/template"
2425
2526 "github.com/arduino/arduino-lint/internal/configuration"
@@ -222,12 +223,18 @@ func (results Type) JSONReport() string {
222223
223224// jsonReportRaw returns the report marshalled into JSON format in byte encoding.
224225func (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 )
226233 if err != nil {
227234 panic (fmt .Sprintf ("Error while formatting rules report: %v" , err ))
228235 }
229236
230- return reportJSON
237+ return marshalledReportBuffer . Bytes ()
231238}
232239
233240// WriteReport writes a report for all projects to the specified file.
You can’t perform that action at this time.
0 commit comments