Cosmos-sdk: Seeing unicode in raw log for a "q tx"

Created on 11 Mar 2020  Â·  3Comments  Â·  Source: cosmos/cosmos-sdk

Summary of Bug

I tried to send token ubnt to Bob, but I don't have token ubnt... only token bnt. TX raw log:

489946469bnt \u003c 1ubn" means "489946469bnt < 1ubnt

You can see unicode there showing:

\u003c

Which is the "<" sign.

Version

cosmos-sdk v0.38.1
go version go1.13.6 darwin/amd64

Steps to Reproduce

Try to send a currency denom you don't have enough of (or perhaps at all) and then look at the raw log of the result.

@alessio We discussed this yesterday, btw. Just in case you were going to file.


For Admin Use

  • [ ] Not duplicate issue
  • [ ] Appropriate labels applied
  • [ ] Appropriate contributors tagged
  • [ ] Contributor assigned/self-assigned
UX bug good first issue

All 3 comments

This is a long standing issue and is due to how Golang JSON encoding works:

String values encode as JSON strings coerced to valid UTF-8, replacing invalid
bytes with the Unicode replacement rune. So that the JSON will be safe to
embed inside HTML <script> tags, the string is encoded using HTMLEscape,
which replaces "<", ">", "&", U+2028, and U+2029 are escaped to
"\u003c","\u003e", "\u0026", "\u2028", and "\u2029". This replacement can
be disabled when using an Encoder, by calling SetEscapeHTML(false).

_(from https://golang.org/pkg/encoding/json/#Marshal)_

In my very humble opinion, the simplest solution would be to replace symbols with human readable expressions that carry the same meaning, e.g. < should become smaller than, and so on.

Thanks @njmurarka for taking the time to report this bug and help to make the Cosmos SDK better.
A patch is provided in the aforementioned PR.

ACK @alessio

Was this page helpful?
0 / 5 - 0 ratings