Skip to content

Commit

Permalink
Merge pull request #7 from Dewberry/feature/url-encoding
Browse files Browse the repository at this point in the history
marshall response JSON without escaping HTML characters
  • Loading branch information
slawler authored Feb 9, 2024
2 parents e252550 + c1d25f5 commit e27c71d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions papigoplug/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package papigoplug

import (
"bytes"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit e27c71d

Please sign in to comment.