From c1d25f5f43a61ff46e7424bb9a8f80b542ae7d42 Mon Sep 17 00:00:00 2001 From: Anton Kopti Date: Thu, 8 Feb 2024 15:54:02 -0500 Subject: [PATCH] marshall response JSON without escaping HTML characters --- papigoplug/utils.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/papigoplug/utils.go b/papigoplug/utils.go index c477499..5cd7246 100644 --- a/papigoplug/utils.go +++ b/papigoplug/utils.go @@ -1,6 +1,7 @@ package papigoplug import ( + "bytes" "encoding/json" "errors" "fmt" @@ -67,11 +68,16 @@ type pluginResults struct { // PrintResults encodes the provided map into a JSON string within key "plugin_results" and prints that. // This function must be called at the end of the program. func PrintResults(results map[string]interface{}) (err error) { - bytes, err := json.Marshal(pluginResults{Results: results}) - if err != nil { + var buf bytes.Buffer + encoder := json.NewEncoder(&buf) + encoder.SetEscapeHTML(false) // Do not escape HTML characters + + if err = encoder.Encode(pluginResults{Results: results}); err != nil { return } - fmt.Println(string(bytes)) + + // Use strings.TrimSpace to remove the trailing newline added by Encode. + fmt.Println(buf.String()) return }