Skip to content

Commit dc31757

Browse files
author
Matthieu Vachon
committed
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.
1 parent f5b94e1 commit dc31757

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

api.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,12 +653,14 @@ func enc(v interface{}) (io.Reader, error) {
653653
return nil, nil
654654
}
655655

656-
cnt, err := json.Marshal(v)
656+
buffer := &bytes.Buffer{}
657+
encoder := json.NewEncoder(buffer)
658+
encoder.SetEscapeHTML(false)
659+
660+
err := encoder.Encode(v)
657661
if err != nil {
658662
return nil, err
659663
}
660664

661-
//fmt.Println("BODY", string(cnt))
662-
663-
return bytes.NewReader(cnt), nil
665+
return buffer, nil
664666
}

0 commit comments

Comments
 (0)