From dc31757533135f3380a5dd5143531eef82fdbeff Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Wed, 3 Apr 2019 15:19:02 -0400 Subject: [PATCH] Avoid escaping HTML when encoding API body The default behavior of Golang encoder via `json.Marshal` is to escape HTMl characters by default with a Unicode sequence. However, nodeos does not correctly handles those creating a a string with the Unicode escape sequence instead of interpreting the sequence a character. To fix that, we now use the json.Encoder to encode and just before encoding, we set escape HTML to false. --- api.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api.go b/api.go index c4345c3a..1cb8e15b 100644 --- a/api.go +++ b/api.go @@ -653,12 +653,14 @@ func enc(v interface{}) (io.Reader, error) { return nil, nil } - cnt, err := json.Marshal(v) + buffer := &bytes.Buffer{} + encoder := json.NewEncoder(buffer) + encoder.SetEscapeHTML(false) + + err := encoder.Encode(v) if err != nil { return nil, err } - //fmt.Println("BODY", string(cnt)) - - return bytes.NewReader(cnt), nil + return buffer, nil }