Browse Source

cmn: fix HexBytes.MarshalJSON

pull/1842/head
Ethan Buchman 7 years ago
parent
commit
2bb538b150
2 changed files with 3 additions and 3 deletions
  1. +1
    -1
      common/bytes.go
  2. +2
    -2
      common/bytes_test.go

+ 1
- 1
common/bytes.go View File

@ -26,7 +26,7 @@ func (bz HexBytes) MarshalJSON() ([]byte, error) {
jbz := make([]byte, len(s)+2) jbz := make([]byte, len(s)+2)
jbz[0] = '"' jbz[0] = '"'
copy(jbz[1:], []byte(s)) copy(jbz[1:], []byte(s))
jbz[1] = '"'
jbz[len(jbz)-1] = '"'
return jbz, nil return jbz, nil
} }


+ 2
- 2
common/bytes_test.go View File

@ -35,8 +35,8 @@ func TestJSONMarshal(t *testing.T) {
expected string expected string
}{ }{
{[]byte(``), `{"B1":"","B2":""}`}, {[]byte(``), `{"B1":"","B2":""}`},
{[]byte(``), `{"B1":"","B2":""}`},
{[]byte(``), `{"B1":"","B2":""}`},
{[]byte(`a`), `{"B1":"YQ==","B2":"61"}`},
{[]byte(`abc`), `{"B1":"YWJj","B2":"616263"}`},
} }
for i, tc := range cases { for i, tc := range cases {


Loading…
Cancel
Save