@@ -14,7 +14,6 @@ import (
14
14
log "github.com/sirupsen/logrus"
15
15
"io/ioutil"
16
16
"k8s.io/client-go/util/jsonpath"
17
- "math/big"
18
17
"math/rand"
19
18
"net/http"
20
19
"net/url"
@@ -402,14 +401,11 @@ func jsonPath(query, toMatch string) interface{} {
402
401
403
402
// Jsonpath library converts large int into a string with scientific notion, the following
404
403
// reverts that process to avoid mismatching when using the jsonpath result for csv data lookup
405
- // Handle large integers in scientific notation by converting back to big.Int
406
- if isScientific (result ) {
407
- // If result is in scientific notation, try converting to a big.Int
408
- bigInt := new (big.Int )
409
- bigInt , success := bigIntFromString (result )
410
- if success {
411
- result = bigInt .String () // Convert back to string representation of the big integer
412
- }
404
+ floatResult , err := strconv .ParseFloat (result , 64 )
405
+ // if the string is a float and a whole number
406
+ if err == nil && floatResult == float64 (int64 (floatResult )) {
407
+ intResult := int (floatResult )
408
+ result = strconv .Itoa (intResult )
413
409
}
414
410
415
411
// convert to array data if applicable
@@ -424,27 +420,6 @@ func jsonPath(query, toMatch string) interface{} {
424
420
return arrayData
425
421
}
426
422
427
- // isScientific checks if a string is in scientific notation (e.g., "1.349599e+37")
428
- func isScientific (value string ) bool {
429
- return strings .Contains (value , "e" ) || strings .Contains (value , "E" )
430
- }
431
-
432
- // bigIntFromString converts a string representing a number (potentially in scientific notation) to big.Int
433
- func bigIntFromString (value string ) (* big.Int , bool ) {
434
- // Parse the string as a big.Float to handle scientific notation
435
- flt := new (big.Float )
436
- flt , _ , err := big .ParseFloat (value , 10 , 0 , big .ToNearestEven )
437
- if err != nil {
438
- return nil , false
439
- }
440
-
441
- // Convert the big.Float to big.Int (rounding down)
442
- bigInt := new (big.Int )
443
- flt .Int (bigInt )
444
-
445
- return bigInt , true
446
- }
447
-
448
423
func xPath (query , toMatch string ) string {
449
424
result , err := XpathExecution (query , toMatch )
450
425
if err != nil {
0 commit comments