Skip to content

Commit

Permalink
Merge pull request #334 from yarpc/dev
Browse files Browse the repository at this point in the history
Release v0.19.1
  • Loading branch information
AllenLuUber authored Apr 5, 2021
2 parents 204b64a + fd09a63 commit 8edf8ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changelog
=========

# 0.19.1 (2021-04-02)
* Fix byte parsing to allow 8-bit signed integers to match the Thrift spec & other language implementations.

# 0.19.0 (2021-03-24)
* Add support for gRPC streaming:
- Support of benchmark and curl-like fashion mode
Expand Down
13 changes: 9 additions & 4 deletions thrift/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"math"
"strconv"
"strings"
)
Expand Down Expand Up @@ -115,11 +116,15 @@ func parseBinaryList(vl []interface{}) ([]byte, error) {
bs := make([]byte, 0, len(vl))
for _, v := range vl {
switch v := v.(type) {
// YAML uses int for all small values. For large values, it may use int64 or uint64
// but those are not valid bool values anyway, so we don't need to check them.
case int:
// YAML uses int for all small values. For large values, it may use int64 or uint64
// but those are not valid bool values anyway, so we don't need to check them.
if v < 0 || v >= (1<<8) {
return nil, fmt.Errorf("failed to parse list of bytes: %v is not a byte", v)
// from https://thrift.apache.org/docs/types, byte is an 8-bit signed integer
// In Go, byte is an unsigned int8 (uint8) which has a range [0, 255].
// In Java, byte is a signed int8 which has a range of [-128,127].
// To make both sides happy, check between [-128,255]
if v < math.MinInt8 || v > math.MaxUint8 {
return nil, fmt.Errorf("failed to parse list of bytes: %v is not a valid thrift byte", v)
}
bs = append(bs, byte(v))
case string:
Expand Down
16 changes: 16 additions & 0 deletions thrift/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,18 @@ func TestParseBinary(t *testing.T) {
value: []interface{}{65, 66},
want: []byte("AB"),
},
{
value: []interface{}{1, -1},
want: []byte{0x1, 0xff},
},
{
value: []interface{}{-128, 127, 255}, // boundary for diff int types
want: []byte{0x80, 0x7f, 0xff},
},
{
value: []interface{}{-1, 255}, // overflow causes the same results
want: []byte{0xff, 0xff},
},
{
value: []interface{}{104, "ello", "", " ", "world"},
want: []byte("hello world"),
Expand All @@ -292,6 +304,10 @@ func TestParseBinary(t *testing.T) {
value: []interface{}{256},
errMsg: "failed to parse list of bytes",
},
{
value: []interface{}{-129},
errMsg: "failed to parse list of bytes",
},
{
value: []interface{}{1.5},
errMsg: "can only parse list of bytes",
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ package main

// versionString is the sem-ver version string for yab.
// It will be bumped explicitly on releases.
var versionString = "0.19.0"
var versionString = "0.19.1"

0 comments on commit 8edf8ca

Please sign in to comment.