File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 4
4
"bytes"
5
5
"errors"
6
6
"fmt"
7
+ "strings"
7
8
)
8
9
9
10
// A Config node represents the root node of a Logstash configuration.
@@ -407,7 +408,14 @@ func (na NumberAttribute) String() string {
407
408
408
409
// ValueString returns the value of the node as a string representation.
409
410
func (na NumberAttribute ) ValueString () string {
410
- return fmt .Sprintf ("%v" , na .Value ())
411
+ value := fmt .Sprintf ("%g" , na .Value ())
412
+ if strings .Contains (value , "e" ) {
413
+ if float64 (int64 (na .Value ())+ 0 ) == na .Value () {
414
+ return fmt .Sprintf ("%d" , int64 (na .Value ()))
415
+ }
416
+ return strings .TrimRight (fmt .Sprintf ("%.10f" , na .Value ()), "0" )
417
+ }
418
+ return value
411
419
}
412
420
413
421
// CommentBlock returns the comment of the node.
Original file line number Diff line number Diff line change @@ -345,6 +345,29 @@ output {}
345
345
# Comment
346
346
}
347
347
}
348
+ ` ,
349
+ },
350
+ // https://github.com/magnusbaeck/logstash-filter-verifier/issues/104
351
+ {
352
+ name : "large numbers with and without precission" ,
353
+ input : `filter {
354
+ mutate {
355
+ add_field => {
356
+ "largeint" => 2000000
357
+ "largeint_negative" => -2000000
358
+ "int32max" => 2147483647
359
+ "int32max_negative" => -2147483647
360
+ "float_with_5_precision" => 0.00001
361
+ "float_with_5_precision_negative" => -0.00001
362
+ "float_with_10_precision" => 0.0000000001
363
+ "float_with_10_precision_negative" => -0.0000000001
364
+ "largefloat_with_10_precision" => 2000000.0000000005
365
+ "largefloat_with_10_precision_negative" => -2000000.0000000005
366
+ "int32max_with_10_precision" => 2147483647.0000009537
367
+ "int32max_with_10_precision_negative" => -2147483647.0000009537
368
+ }
369
+ }
370
+ }
348
371
` ,
349
372
},
350
373
}
You can’t perform that action at this time.
0 commit comments