Skip to content

Commit

Permalink
fix:(j2t/native) panic when fieldmap is empty (#76)
Browse files Browse the repository at this point in the history
* test

* fix:(j2t) should check if all names are empty
  • Loading branch information
AsterDY authored Sep 24, 2024
1 parent 3c00b4d commit 63139a6
Show file tree
Hide file tree
Showing 10 changed files with 53,044 additions and 52,739 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CFLAGS_avx := -msse -mno-sse4 -mavx -mpclmul -mno-avx2 -mstack-alignment=0 -DUS
CFLAGS_avx2 := -msse -mno-sse4 -mavx -mpclmul -mavx2 -mstack-alignment=0 -DUSE_AVX=1 -DUSE_AVX2=1
CFLAGS_sse := -msse -mno-sse4 -mno-avx -mno-avx2 -mpclmul

CC_amd64 := clang
CC_amd64 := /opt/homebrew/Cellar/llvm\@14/14.0.6/bin/clang
ASM2ASM_amd64 := tools/asm2asm/asm2asm.py

CFLAGS := -mno-red-zone
Expand Down
16 changes: 16 additions & 0 deletions conv/j2t/conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,3 +1552,19 @@ func TestSimpleArgs(t *testing.T) {
require.Equal(t, exp, out)
})
}

func TestEmptyStruct(t *testing.T) {
desc, err := thrift.NewDescritorFromContent(context.Background(), "a/b/main.thrift", `
struct Req {}
service Svc {
void Method(1: Req req)
}
`, nil, true)
require.NoError(t, err)
reqDesc := desc.Functions()["Method"].Request().Struct().FieldById(1).Type()
cv := NewBinaryConv(conv.Options{})
out, err := cv.Do(context.Background(), reqDesc, []byte(`{"UNKNOWN":1}`))
require.NoError(t, err)
fmt.Printf("%+v", out)
}
8 changes: 4 additions & 4 deletions conv/j2t/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func isJsonString(val string) bool {
if len(val) < 2 {
return false
}
c := json.SkipBlank(val, 0)

c := json.SkipBlank(val, 0)
if c < 0 {
return false
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func (self *BinaryConv) writeStringValue(ctx context.Context, buf *[]byte, f *th
if err := self.doNative(ctx, rt.Str2Mem(val), f.Type(), &p.Buf, req, false); err != nil {
return newError(meta.ErrConvert, fmt.Sprintf("failed to convert value of field '%s'", f.Name()), err)
}
// try text encoding, see thrift.EncodeText
// try text encoding, see thrift.EncodeText
} else {
return newError(meta.ErrConvert, fmt.Sprintf("unsupported http-mapping encoding %v for '%s'", enc, f.Name()), nil)
}
Expand All @@ -181,7 +181,7 @@ BACK:
return nil
}

func (self *BinaryConv)writeRequestBaseToThrift(ctx context.Context, buf *[]byte, field *thrift.FieldDescriptor) error {
func (self *BinaryConv) writeRequestBaseToThrift(ctx context.Context, buf *[]byte, field *thrift.FieldDescriptor) error {
var b *base.Base
if bobj := ctx.Value(conv.CtxKeyThriftReqBase); bobj != nil {
if v, ok := bobj.(*base.Base); ok && v != nil {
Expand Down
Loading

0 comments on commit 63139a6

Please sign in to comment.