diff --git a/common/bytes.go b/common/bytes.go index 1ec880c2..ba81bbe9 100644 --- a/common/bytes.go +++ b/common/bytes.go @@ -26,7 +26,7 @@ func (bz HexBytes) MarshalJSON() ([]byte, error) { jbz := make([]byte, len(s)+2) jbz[0] = '"' copy(jbz[1:], []byte(s)) - jbz[1] = '"' + jbz[len(jbz)-1] = '"' return jbz, nil } diff --git a/common/bytes_test.go b/common/bytes_test.go index 3e693b23..9e11988f 100644 --- a/common/bytes_test.go +++ b/common/bytes_test.go @@ -35,8 +35,8 @@ func TestJSONMarshal(t *testing.T) { expected string }{ {[]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 {