Merge pull request #15029 from karalabe/rlp-raw-decode

rlp: fix decoding long strings into RawValue types
This commit is contained in:
Péter Szilágyi 2017-08-24 13:32:45 +03:00 committed by GitHub
commit 20b818d206
2 changed files with 25 additions and 10 deletions

View File

@ -693,7 +693,7 @@ func (s *Stream) Raw() ([]byte, error) {
return nil, err return nil, err
} }
if kind == String { if kind == String {
puthead(buf, 0x80, 0xB8, size) puthead(buf, 0x80, 0xB7, size)
} else { } else {
puthead(buf, 0xC0, 0xF7, size) puthead(buf, 0xC0, 0xF7, size)
} }

View File

@ -256,16 +256,31 @@ func TestStreamList(t *testing.T) {
} }
func TestStreamRaw(t *testing.T) { func TestStreamRaw(t *testing.T) {
s := NewStream(bytes.NewReader(unhex("C58401010101")), 0) tests := []struct {
s.List() input string
output string
want := unhex("8401010101") }{
raw, err := s.Raw() {
if err != nil { "C58401010101",
t.Fatal(err) "8401010101",
},
{
"F842B84001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
"B84001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
},
} }
if !bytes.Equal(want, raw) { for i, tt := range tests {
t.Errorf("raw mismatch: got %x, want %x", raw, want) s := NewStream(bytes.NewReader(unhex(tt.input)), 0)
s.List()
want := unhex(tt.output)
raw, err := s.Raw()
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(want, raw) {
t.Errorf("test %d: raw mismatch: got %x, want %x", i, raw, want)
}
} }
} }