Decode: ensure signed numbers don't start with an underscore (#698)

This commit is contained in:
Cameron Moore
2021-12-04 15:56:48 -06:00
committed by GitHub
parent f53bc740c1
commit 6cd86876b8
2 changed files with 16 additions and 3 deletions
+7 -2
View File
@@ -386,8 +386,13 @@ func parseIntDec(b []byte) (int64, error) {
}
func checkAndRemoveUnderscoresIntegers(b []byte) ([]byte, error) {
if b[0] == '_' {
return nil, newDecodeError(b[0:1], "number cannot start with underscore")
start := 0
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] == '_' {
+9 -1
View File
@@ -2306,9 +2306,17 @@ func TestUnmarshalDecodeErrors(t *testing.T) {
data: `flt8 = 224_617.445_991__228`,
},
{
desc: "float with double _",
desc: "float with double .",
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",
data: `a = 0f2`,