diff --git a/encode_value.go b/encode_value.go index 681dc691..68c936d5 100644 --- a/encode_value.go +++ b/encode_value.go @@ -49,6 +49,10 @@ func getEncoder(typ reflect.Type) encoderFunc { } func _getEncoder(typ reflect.Type) encoderFunc { + if typ == reflectValueType { + return encodeUnsupportedValue + } + kind := typ.Kind() if kind == reflect.Ptr { diff --git a/ext_test.go b/ext_test.go index 7af6d01d..ae4bc53f 100644 --- a/ext_test.go +++ b/ext_test.go @@ -3,12 +3,13 @@ package msgpack_test import ( "bytes" "encoding/hex" + "reflect" "testing" "time" - "github.com/stretchr/testify/require" "github.com/Basekick-Labs/msgpack/v6" "github.com/Basekick-Labs/msgpack/v6/msgpcode" + "github.com/stretchr/testify/require" ) func init() { @@ -171,3 +172,8 @@ func TestDecodeCustomPayload(t *testing.T) { t.Fatalf("got %q, wanted %q", payload, wanted) } } + +func TestMarshalReflectValueInInterfaceMap(t *testing.T) { + _, err := msgpack.Marshal(map[string]interface{}{"value": reflect.ValueOf("text")}) + require.EqualError(t, err, "msgpack: Encode(unsupported reflect.Value)") +} diff --git a/types.go b/types.go index 1a397be0..c8800f55 100644 --- a/types.go +++ b/types.go @@ -10,7 +10,10 @@ import ( "github.com/vmihailenco/tagparser/v2" ) -var errorType = reflect.TypeOf((*error)(nil)).Elem() +var ( + errorType = reflect.TypeOf((*error)(nil)).Elem() + reflectValueType = reflect.TypeOf(reflect.Value{}) +) var ( customEncoderType = reflect.TypeOf((*CustomEncoder)(nil)).Elem()