Decode: ensure signed numbers don't start with an underscore (#698)
This commit is contained in:
@@ -386,8 +386,13 @@ func parseIntDec(b []byte) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkAndRemoveUnderscoresIntegers(b []byte) ([]byte, error) {
|
func checkAndRemoveUnderscoresIntegers(b []byte) ([]byte, error) {
|
||||||
if b[0] == '_' {
|
start := 0
|
||||||
return nil, newDecodeError(b[0:1], "number cannot start with underscore")
|
if b[start] == '+' || b[start] == '-' {
|
||||||
|
start++
|
||||||
|
}
|
||||||
|
|
||||||
|
if b[start] == '_' {
|
||||||
|
return nil, newDecodeError(b[start:start+1], "number cannot start with underscore")
|
||||||
}
|
}
|
||||||
|
|
||||||
if b[len(b)-1] == '_' {
|
if b[len(b)-1] == '_' {
|
||||||
|
|||||||
+9
-1
@@ -2306,9 +2306,17 @@ func TestUnmarshalDecodeErrors(t *testing.T) {
|
|||||||
data: `flt8 = 224_617.445_991__228`,
|
data: `flt8 = 224_617.445_991__228`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "float with double _",
|
desc: "float with double .",
|
||||||
data: `flt8 = 1..2`,
|
data: `flt8 = 1..2`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "number with plus sign and leading underscore",
|
||||||
|
data: `a = +_0`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "number with negative sign and leading underscore",
|
||||||
|
data: `a = -_0`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "int with wrong base",
|
desc: "int with wrong base",
|
||||||
data: `a = 0f2`,
|
data: `a = 0f2`,
|
||||||
|
|||||||
Reference in New Issue
Block a user