Skip to content

Commit

Permalink
Decode: ensure signed exponents don't start with an underscore (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
moorereason authored Dec 6, 2021
1 parent b37e11d commit 8bbb519
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down

0 comments on commit 8bbb519

Please sign in to comment.