From 8bbb51947738eee5a28e59554425c89bbb962a9f Mon Sep 17 00:00:00 2001 From: Cameron Moore Date: Sun, 5 Dec 2021 19:02:19 -0600 Subject: [PATCH] Decode: ensure signed exponents don't start with an underscore (#699) --- decode.go | 4 ++++ unmarshaler_test.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/decode.go b/decode.go index 60eebea..42678cf 100644 --- a/decode.go +++ b/decode.go @@ -465,6 +465,10 @@ func checkAndRemoveUnderscoresFloats(b []byte) ([]byte, error) { return nil, newDecodeError(b[i+1:i+2], "cannot have underscore before exponent") } before = false + case '+', '-': + // signed exponents + cleaned = append(cleaned, c) + before = false case 'e', 'E': if i < len(b)-1 && b[i+1] == '_' { return nil, newDecodeError(b[i+1:i+2], "cannot have underscore after exponent") diff --git a/unmarshaler_test.go b/unmarshaler_test.go index 2e7e81b..39915e7 100644 --- a/unmarshaler_test.go +++ b/unmarshaler_test.go @@ -2317,6 +2317,14 @@ func TestUnmarshalDecodeErrors(t *testing.T) { desc: "number with negative sign and leading underscore", data: `a = -_0`, }, + { + desc: "exponent with plus sign and leading underscore", + data: `a = 0e+_0`, + }, + { + desc: "exponent with negative sign and leading underscore", + data: `a = 0e-_0`, + }, { desc: "int with wrong base", data: `a = 0f2`,