This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-seata-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 423a4dc8 fix: preserve head map keys when value is empty (#1070)
423a4dc8 is described below

commit 423a4dc895d05252d2cde147446081bf072f98b1
Author: Zhifan C <[email protected]>
AuthorDate: Sat Mar 28 13:38:13 2026 +0800

    fix: preserve head map keys when value is empty (#1070)
    
    * fix: preserve head map keys when value is empty
    
    * test: cover empty head map keys
    
    ---------
    
    Co-authored-by: Konnyaku <[email protected]>
    Co-authored-by: ThunGuo <[email protected]>
---
 pkg/remoting/getty/readwriter.go      |  3 +--
 pkg/remoting/getty/readwriter_test.go | 50 +++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/pkg/remoting/getty/readwriter.go b/pkg/remoting/getty/readwriter.go
index 7a0cfe1a..9b254141 100644
--- a/pkg/remoting/getty/readwriter.go
+++ b/pkg/remoting/getty/readwriter.go
@@ -212,7 +212,7 @@ func decodeHeapMap(in *bytes.ByteBuffer, length uint16) 
map[string]string {
 
                valueLength := bytes.ReadUInt16(in)
                if valueLength == 0 {
-                       key = ""
+                       value = ""
                } else {
                        valueBytes := make([]byte, valueLength)
                        in.Read(valueBytes)
@@ -221,7 +221,6 @@ func decodeHeapMap(in *bytes.ByteBuffer, length uint16) 
map[string]string {
 
                res[key] = value
                readedLength += 4 + keyLength + valueLength
-               fmt.Sprintln("done")
        }
        return res
 }
diff --git a/pkg/remoting/getty/readwriter_test.go 
b/pkg/remoting/getty/readwriter_test.go
index 0bf93642..bc034c1c 100644
--- a/pkg/remoting/getty/readwriter_test.go
+++ b/pkg/remoting/getty/readwriter_test.go
@@ -51,3 +51,53 @@ func TestRpcPackageHandler(t *testing.T) {
 
        assert.Equal(t, msg, msg2)
 }
+
+func TestRpcPackageHandler_EmptyHeadMapValue(t *testing.T) {
+       msg := message.RpcMessage{
+               ID:         1124,
+               Type:       message.GettyRequestTypeRequestSync,
+               Codec:      byte(codec.CodecTypeSeata),
+               Compressor: byte(1),
+               HeadMap: map[string]string{
+                       "name": "Jack",
+                       "note": "",
+               },
+               Body: message.GlobalBeginRequest{
+                       Timeout:         2 * time.Second,
+                       TransactionName: "SeataGoTransaction",
+               },
+       }
+
+       codec := RpcPackageHandler{}
+       bytes, err := codec.Write(nil, msg)
+       assert.Nil(t, err)
+       msg2, _, err := codec.Read(nil, bytes)
+       assert.Nil(t, err)
+
+       assert.Equal(t, msg, msg2)
+}
+
+func TestRpcPackageHandler_EmptyHeadMapKey(t *testing.T) {
+       msg := message.RpcMessage{
+               ID:         1125,
+               Type:       message.GettyRequestTypeRequestSync,
+               Codec:      byte(codec.CodecTypeSeata),
+               Compressor: byte(1),
+               HeadMap: map[string]string{
+                       "":     "value",
+                       "name": "Jack",
+               },
+               Body: message.GlobalBeginRequest{
+                       Timeout:         2 * time.Second,
+                       TransactionName: "SeataGoTransaction",
+               },
+       }
+
+       codec := RpcPackageHandler{}
+       bytes, err := codec.Write(nil, msg)
+       assert.Nil(t, err)
+       msg2, _, err := codec.Read(nil, bytes)
+       assert.Nil(t, err)
+
+       assert.Equal(t, msg, msg2)
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to