diff --git a/bint.go b/bint.go index 956a842..baf2f97 100644 --- a/bint.go +++ b/bint.go @@ -144,8 +144,8 @@ func parseBint(s []byte) (bool, bint, uint8, error) { return false, bint{}, 0, errInvalidFormat(s) } - // prevent "-.123" or "+.123" - if s[pos] == '.' { + // prevent "-.123" or "+.123", and a second sign as in "-+123" that big.Int would read as a sign again + if s[pos] < '0' || s[pos] > '9' { return false, bint{}, 0, errInvalidFormat(s) } diff --git a/decimal_test.go b/decimal_test.go index 75a467b..80ccb5c 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -131,6 +131,12 @@ func TestParse(t *testing.T) { {"+340282366920938463463374607431768211459", "340282366920938463463374607431768211459", nil}, {"340282366920938463463374607431768211459.", "", fmt.Errorf("%w: can't parse '340282366920938463463374607431768211459.'", ErrInvalidFormat)}, {"--340282366920938463463374607431768211459", "", fmt.Errorf("%w: can't parse '--340282366920938463463374607431768211459'", ErrInvalidFormat)}, + {"-+1234567890123456789012345678901234567890123456", "", fmt.Errorf("%w: can't parse '-+1234567890123456789012345678901234567890123456'", ErrInvalidFormat)}, + {"-+340282366920938463463374607431768211459.123", "", fmt.Errorf("%w: can't parse '-+340282366920938463463374607431768211459.123'", ErrInvalidFormat)}, + {"+-1234567890123456789012345678901234567890123456", "", fmt.Errorf("%w: can't parse '+-1234567890123456789012345678901234567890123456'", ErrInvalidFormat)}, + {"++1234567890123456789012345678901234567890123456", "", fmt.Errorf("%w: can't parse '++1234567890123456789012345678901234567890123456'", ErrInvalidFormat)}, + {"--1234567890123456789012345678901234567890123456", "", fmt.Errorf("%w: can't parse '--1234567890123456789012345678901234567890123456'", ErrInvalidFormat)}, + {"-+123", "", fmt.Errorf("%w: can't parse '-+123'", ErrInvalidFormat)}, {".1234567890123456789012345678901234567890123456", "", fmt.Errorf("%w: can't parse '.1234567890123456789012345678901234567890123456'", ErrInvalidFormat)}, {"+.1234567890123456789012345678901234567890123456", "", fmt.Errorf("%w: can't parse '+.1234567890123456789012345678901234567890123456'", ErrInvalidFormat)}, {"-.1234567890123456789012345678901234567890123456", "", fmt.Errorf("%w: can't parse '-.1234567890123456789012345678901234567890123456'", ErrInvalidFormat)},