Skip to content

Commit 4fc4320

Browse files
authored
Merge pull request #35 from francoispqt/fix/float-one-decimal
add test for 1 decimal float and fix bug introducedn in previous patch
2 parents b8dc210 + b713369 commit 4fc4320

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

decode_number_float.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (dec *Decoder) getFloat() (float64, error) {
109109
dec.cursor = i
110110
break
111111
}
112-
if end >= dec.length || end <= start {
112+
if end >= dec.length || end < start {
113113
return 0, dec.raiseInvalidJSONErr(dec.cursor)
114114
}
115115
// then we add both integers
@@ -258,7 +258,7 @@ func (dec *Decoder) getFloat32() (float32, error) {
258258
dec.cursor = i
259259
break
260260
}
261-
if end >= dec.length || end <= start {
261+
if end >= dec.length || end < start {
262262
return 0, dec.raiseInvalidJSONErr(dec.cursor)
263263
}
264264
// then we add both integers

decode_number_float_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ func TestDecoderFloat64(t *testing.T) {
1919
err bool
2020
errType interface{}
2121
}{
22+
{
23+
name: "basic-float",
24+
json: "1.1",
25+
expectedResult: 1.1,
26+
},
2227
{
2328
name: "basic-exponent-positive-positive-exp",
2429
json: "1e2",
@@ -323,6 +328,11 @@ func TestDecoderFloat32(t *testing.T) {
323328
err bool
324329
errType interface{}
325330
}{
331+
{
332+
name: "basic-float",
333+
json: "1.1",
334+
expectedResult: 1.1,
335+
},
326336
{
327337
name: "basic-exponent-positive-positive-exp",
328338
json: "1e2",

0 commit comments

Comments
 (0)