mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Set TimeNotBuiltin msgpack option directly without using BasicHandle
Prevents a situation where when attempting to decode a string into a nil interface, the decoded value would be the encoded slice of bytes instead of the string we need.
This commit is contained in:
committed by
Dan Christian Bogos
parent
df3ae97e57
commit
628df25caa
@@ -265,9 +265,7 @@ func NewCodecMsgpackMarshaler() *CodecMsgpackMarshaler {
|
||||
mh := new(codec.MsgpackHandle)
|
||||
mh.MapType = reflect.TypeOf(map[string]any(nil))
|
||||
mh.RawToString = true
|
||||
mh.BasicHandle = codec.BasicHandle{
|
||||
TimeNotBuiltin: true,
|
||||
}
|
||||
mh.TimeNotBuiltin = true
|
||||
return &CodecMsgpackMarshaler{mh}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,35 @@ func TestMsgpackTime(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStorageDecodeIntoNilIface(t *testing.T) {
|
||||
ms := NewCodecMsgpackMarshaler()
|
||||
|
||||
mp := map[string]any{
|
||||
"key1": "value1",
|
||||
"key2": 2.,
|
||||
}
|
||||
expBytes := []byte{130, 164, 107, 101, 121, 49, 166, 118, 97, 108, 117, 101, 49, 164, 107, 101, 121, 50, 203, 64, 0, 0, 0, 0, 0, 0, 0}
|
||||
b, err := ms.Marshal(mp)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(b, expBytes) {
|
||||
t.Fatalf("expected: %+v,\nreceived: <%+v>", expBytes, b)
|
||||
}
|
||||
|
||||
decodedMap := make(map[string]any)
|
||||
err = ms.Unmarshal(b, &decodedMap)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for key, value := range decodedMap {
|
||||
if value != mp[key] {
|
||||
t.Fatalf("for key %s, expected: %+v,\nreceived: %+v",
|
||||
key, mp[key], value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStorageDestinationContainsPrefixShort(t *testing.T) {
|
||||
dest, err := dm.GetDestination("NAT", true, utils.NonTransactional)
|
||||
precision := dest.containsPrefix("0723")
|
||||
|
||||
Reference in New Issue
Block a user