Fix panic in TryFindUnderlyingTypeScanPlan
Check if CanConvert before calling reflect.Value.Convert
This commit is contained in:
committed by
Jack Christensen
parent
046f497efb
commit
d149d3fe5c
+1
-1
@@ -561,7 +561,7 @@ func TryFindUnderlyingTypeScanPlan(dst any) (plan WrappedScanPlanNextSetter, nex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if nextDstType != nil && dstValue.Type() != nextDstType {
|
if nextDstType != nil && dstValue.Type() != nextDstType && dstValue.CanConvert(nextDstType) {
|
||||||
return &underlyingTypeScanPlan{dstType: dstValue.Type(), nextDstType: nextDstType}, dstValue.Convert(nextDstType).Interface(), true
|
return &underlyingTypeScanPlan{dstType: dstValue.Type(), nextDstType: nextDstType}, dstValue.Convert(nextDstType).Interface(), true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ func init() {
|
|||||||
// Test for renamed types
|
// Test for renamed types
|
||||||
type _string string
|
type _string string
|
||||||
type _bool bool
|
type _bool bool
|
||||||
|
type _uint8 uint8
|
||||||
type _int8 int8
|
type _int8 int8
|
||||||
type _int16 int16
|
type _int16 int16
|
||||||
type _int16Slice []int16
|
type _int16Slice []int16
|
||||||
@@ -453,6 +454,14 @@ func TestMapScanNullToWrongType(t *testing.T) {
|
|||||||
assert.False(t, pn.Valid)
|
assert.False(t, pn.Valid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestScanToSliceOfRenamedUint8(t *testing.T) {
|
||||||
|
m := pgtype.NewMap()
|
||||||
|
var ruint8 []_uint8
|
||||||
|
err := m.Scan(pgtype.Int2ArrayOID, pgx.TextFormatCode, []byte("{2,4}"), &ruint8)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []_uint8{2, 4}, ruint8)
|
||||||
|
}
|
||||||
|
|
||||||
func TestMapScanTextToBool(t *testing.T) {
|
func TestMapScanTextToBool(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
Reference in New Issue
Block a user