Skip to content

Commit

Permalink
Avoid escaping HTML when encoding API body
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Matthieu Vachon committed Apr 3, 2019
1 parent f5b94e1 commit dc31757
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit dc31757

Please sign in to comment.