Skip to content

Commit

Permalink
Decode: use cleaned byte slice throughout parseFloat (#735)
Browse files Browse the repository at this point in the history
Fixes #734
  • Loading branch information
moorereason authored Jan 6, 2022
1 parent e83cf53 commit 146f70e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ func parseFloat(b []byte) (float64, error) {
}

start := 0
if b[0] == '+' || b[0] == '-' {
if cleaned[0] == '+' || cleaned[0] == '-' {
start = 1
}
if b[start] == '0' && isDigit(b[start+1]) {
if cleaned[start] == '0' && isDigit(cleaned[start+1]) {
return 0, newDecodeError(b, "float integer part cannot have leading zeroes")
}

Expand Down
5 changes: 5 additions & 0 deletions unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ func TestUnmarshal_Floats(t *testing.T) {
input: `1.0_e2`,
err: true,
},
{
desc: "leading zero in positive float",
input: `+0_0.0`,
err: true,
},
}

type doc struct {
Expand Down

0 comments on commit 146f70e

Please sign in to comment.