From 7e55f41a59749ead153f6efd8b728ad4e2cdb2e8 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Wed, 23 Dec 2020 01:42:49 +0900 Subject: [PATCH] Fix encoding of nil value for opMarshalText --- encode_vm.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/encode_vm.go b/encode_vm.go index 20af120..60f388d 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -486,10 +486,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte ptr := load(ctxptr, code.idx) isPtr := code.typ.Kind() == reflect.Ptr p := e.ptrToUnsafePtr(ptr) - if p == nil { - b = encodeNull(b) - b = encodeComma(b) - } else if isPtr && *(*unsafe.Pointer)(p) == nil { + if p == nil || isPtr && *(*unsafe.Pointer)(p) == nil { b = append(b, '"', '"', ',') } else { v := *(*interface{})(unsafe.Pointer(&interfaceHeader{