Fix handling of floats with multiple leading zeroes (#4065)
(cherry picked from commit a3500cc33a
)
This commit is contained in:
parent
a877b06d74
commit
29bdb324d6
File diff suppressed because it is too large
Load Diff
|
@ -122,7 +122,7 @@ unsigned =
|
||||||
( digit | ( non_zero_digit digit* ) );
|
( digit | ( non_zero_digit digit* ) );
|
||||||
|
|
||||||
number =
|
number =
|
||||||
( integer ( '.' digit* )? ) | ( '.' digit* );
|
'-'? (digit+ ('.' digit*)? | '.' digit+);
|
||||||
|
|
||||||
scientific =
|
scientific =
|
||||||
number 'e'i ["\-+"]? digit+;
|
number 'e'i ["\-+"]? digit+;
|
||||||
|
|
|
@ -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",
|
name: "multiple fields",
|
||||||
input: []byte("cpu x=42,y=42"),
|
input: []byte("cpu x=42,y=42"),
|
||||||
|
|
Loading…
Reference in New Issue