pgtype: Fix -0 for numeric types
Due to the special case of when the digits string was longer than 1 but only contained the negative sign and a 0, it was incorrectly stripping the 0 and attempting to parse "-" as a number. The solution is to check an extra position along to make sure a trailing 0 is not immediately preceeded by a negetive sign. Fixes #543
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package pgtype_test
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
@@ -188,7 +189,9 @@ func TestNumericSet(t *testing.T) {
|
||||
result *pgtype.Numeric
|
||||
}{
|
||||
{source: float32(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
||||
{source: float32(math.Copysign(0, -1)), result: &pgtype.Numeric{Int: big.NewInt(0), Status: pgtype.Present}},
|
||||
{source: float64(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
||||
{source: float64(math.Copysign(0, -1)), result: &pgtype.Numeric{Int: big.NewInt(0), Status: pgtype.Present}},
|
||||
{source: int8(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
||||
{source: int16(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
||||
{source: int32(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
||||
|
||||
Reference in New Issue
Block a user