From f8b2b03584cccf3c502422b70b51eb723ca2fd43 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Fri, 22 Jan 2021 18:31:07 +0900 Subject: [PATCH] Fix forgot to add key in omitempty field --- encode_vm.go | 8 ++++++++ encode_vm_escaped.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/encode_vm.go b/encode_vm.go index 694ff17..dcea6c1 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -7936,7 +7936,9 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p == 0 || uintptr(array.data) == 0 { code = code.nextField } else { + b = append(b, code.key...) code = code.next + store(ctxptr, code.idx, p) } case opStructFieldSlice: b = append(b, code.key...) @@ -7951,7 +7953,9 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p == 0 || uintptr(slice.data) == 0 { code = code.nextField } else { + b = append(b, code.key...) code = code.next + store(ctxptr, code.idx, p) } case opStructFieldMap: b = append(b, code.key...) @@ -7969,7 +7973,9 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if mlen == 0 { code = code.nextField } else { + b = append(b, code.key...) code = code.next + store(ctxptr, code.idx, p) } } case opStructFieldMapLoad: @@ -7988,7 +7994,9 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if mlen == 0 { code = code.nextField } else { + b = append(b, code.key...) code = code.next + store(ctxptr, code.idx, p) } } case opStructFieldStruct: diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index 839da2c..9a08d36 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -7922,7 +7922,9 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p == 0 || uintptr(array.data) == 0 { code = code.nextField } else { + b = append(b, code.escapedKey...) code = code.next + store(ctxptr, code.idx, p) } case opStructFieldSlice: b = append(b, code.escapedKey...) @@ -7937,7 +7939,9 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p == 0 || uintptr(slice.data) == 0 { code = code.nextField } else { + b = append(b, code.escapedKey...) code = code.next + store(ctxptr, code.idx, p) } case opStructFieldMap: b = append(b, code.escapedKey...) @@ -7955,7 +7959,9 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if mlen == 0 { code = code.nextField } else { + b = append(b, code.escapedKey...) code = code.next + store(ctxptr, code.idx, p) } } case opStructFieldMapLoad: @@ -7974,7 +7980,9 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if mlen == 0 { code = code.nextField } else { + b = append(b, code.escapedKey...) code = code.next + store(ctxptr, code.idx, p) } } case opStructFieldStruct: