knyk-dev opened a new issue, #1069:
URL: https://github.com/apache/incubator-seata-go/issues/1069

   ### ✅ Verification Checklist
   
   - [x] 🔍 I have searched the [existing 
issues](https://github.com/apache/incubator-seata-go/issues) and confirmed this 
is not a duplicate
   - [x] 🛠️ I am willing to try to fix this bug myself.
   
   ### 🚀 Go Version
   
   1.20.14
   
   ### 📦 Seata-go Version
   
   master
   
   ### 💾 Operating System
   
   🐧 Linux
   
   ### 📝 Bug Description
   
   `decodeHeapMap()` assigns `key = ""` when `valueLength == 0`.
   
   As a result, a `HeadMap` entry with an empty string value is decoded under 
`""` instead of its original key. This breaks the encode/decode round trip for 
`RpcMessage.HeadMap`.
   
   If more than one entry has an empty string value, they are all decoded to 
the same empty key and may overwrite each other.
   
   ### 🔄 Steps to Reproduce
   
   Please list the steps to reproduce:
   1. Create an `RpcMessage` with `HeadMap: map[string]string{"name": "Jack", 
"note": ""}`.
   2. Encode it with `RpcPackageHandler.Write`.
   3. Decode it with `RpcPackageHandler.Read`.
   4. Check the decoded `HeadMap`.
   
   Minimal example:
   
   ```go
   msg := message.RpcMessage{
       HeadMap: map[string]string{
           "name": "Jack",
           "note": "",
       },
   }
   
   ### ✅ Expected Behavior
   
   The decoded `HeadMap` should be identical to the original one.
   
   The entry `"note": ""` should still be present after decode.
   
   ### ❌ Actual Behavior
   
   The original key is lost when the value is empty.
   
   In `decodeHeapMap()`, the `valueLength == 0` branch assigns `key = ""`, so 
the decoded map contains an empty key instead of the original one.
   
   
   
   ### 💡 Possible Solution
   
   Keep the decoded key unchanged when `valueLength == 0`, and set `value = ""` 
instead.
   
   There should also be a regression test to verify that a `HeadMap` entry with 
an empty string value survives a full encode/decode round trip.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to