Fix handling of floats with multiple leading zeroes (#4065)

This commit is contained in:
Daniel Nelson 2018-04-23 13:29:49 -07:00 committed by GitHub
parent 0bedc11d2d
commit b9c5e88c22
3 changed files with 15712 additions and 14997 deletions

File diff suppressed because it is too large Load Diff

View File

@ -122,7 +122,7 @@ unsigned =
( digit | ( non_zero_digit digit* ) );
number =
( integer ( '.' digit* )? ) | ( '.' digit* );
'-'? (digit+ ('.' digit*)? | '.' digit+);
scientific =
number 'e'i ["\-+"]? digit+;

View File

@ -517,6 +517,55 @@ var tests = []struct {
},
},
},
{
name: "float without integer digits negative",
input: []byte("cpu value=-.42"),
results: []Result{
Result{
Name: Measurement,
Value: []byte("cpu"),
},
Result{
Name: FieldKey,
Value: []byte("value"),
},
Result{
Name: FieldFloat,
Value: []byte("-.42"),
},
},
},
{
name: "float with multiple leading 0",
input: []byte("cpu value=00.42"),
results: []Result{
Result{
Name: Measurement,
Value: []byte("cpu"),
},
Result{
Name: FieldKey,
Value: []byte("value"),
},
Result{
Name: FieldFloat,
Value: []byte("00.42"),
},
},
},
{
name: "invalid float with only dot",
input: []byte("cpu value=."),
results: []Result{
Result{
Name: Measurement,
Value: []byte("cpu"),
},
Result{
err: ErrFieldParse,
},
},
},
{
name: "multiple fields",
input: []byte("cpu x=42,y=42"),