diff --git a/internal/field/field.go b/internal/field/field.go index a14d9d89..6ab30b89 100644 --- a/internal/field/field.go +++ b/internal/field/field.go @@ -184,9 +184,13 @@ func ValueOf(data string) Value { } else if math.IsNaN(num) { return Value{kind: Number, data: "NaN", num: nan} } - return Value{kind: Number, data: data, num: num} - } - if gjson.Valid(data) { + // Make sure that this is a JSON compatible number. + // For example, "000123" and "000_123" both parse as floats but aren't + // really Numbers that can be represents in JSON. + if gjson.Valid(data) { + return Value{kind: Number, data: data, num: num} + } + } else if gjson.Valid(data) { data = strings.TrimSpace(data) r := gjson.Parse(data) switch r.Type { diff --git a/internal/field/field_test.go b/internal/field/field_test.go index 26830a03..31fdf751 100644 --- a/internal/field/field_test.go +++ b/internal/field/field_test.go @@ -130,5 +130,6 @@ func TestWeight(t *testing.T) { } func TestNumber(t *testing.T) { - assert.Assert(ValueOf("012").Num() == 12) + assert.Assert(ValueOf("12").Num() == 12) + assert.Assert(ValueOf("012").Num() == 0) } diff --git a/internal/field/list_test.go b/internal/field/list_test.go index 769fafe8..9fc7a5e2 100644 --- a/internal/field/list_test.go +++ b/internal/field/list_test.go @@ -63,7 +63,7 @@ func TestList(t *testing.T) { }) assert.Assert(names == "fellohellojellonello") assert.Assert(datas == "123456789012") - assert.Assert(nums == 1380) + assert.Assert(nums == 1368) names = "" datas = ""