Skip to content

Commit 25457ed

Browse files
authored
Revert "bugfix - resolve issue #1155" (#1157)
* Revert "better version of fix" This reverts commit 16dd451. * Revert "handling for big int" This reverts commit dacd2be. * Revert "bugfix - resolve issue #1155" This reverts commit fa9da57.
1 parent 16dd451 commit 25457ed

File tree

2 files changed

+5
-51
lines changed

2 files changed

+5
-51
lines changed

core/util/util.go

+5-30
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
log "github.com/sirupsen/logrus"
1515
"io/ioutil"
1616
"k8s.io/client-go/util/jsonpath"
17-
"math/big"
1817
"math/rand"
1918
"net/http"
2019
"net/url"
@@ -402,14 +401,11 @@ func jsonPath(query, toMatch string) interface{} {
402401

403402
// Jsonpath library converts large int into a string with scientific notion, the following
404403
// 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)
413409
}
414410

415411
// convert to array data if applicable
@@ -424,27 +420,6 @@ func jsonPath(query, toMatch string) interface{} {
424420
return arrayData
425421
}
426422

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-
448423
func xPath(query, toMatch string) string {
449424
result, err := XpathExecution(query, toMatch)
450425
if err != nil {

core/util/util_test.go

-21
Original file line numberDiff line numberDiff line change
@@ -234,27 +234,6 @@ func Test_CopyMap(t *testing.T) {
234234
Expect(newMap["second"]).To(Equal("2"))
235235
}
236236

237-
func Test_JsonPathMethod_WithBigFloatingNumber(t *testing.T) {
238-
239-
RegisterTestingT(t)
240-
res := jsonPath("$.registrant", `{"registrant":"13495985898986869898697879879987978978.12345566777"}`)
241-
Expect(res).To(Equal("13495985898986869898697879879987978978.12345566777"))
242-
}
243-
244-
func Test_JsonPathMethod_WithBigIntegerNumber(t *testing.T) {
245-
246-
RegisterTestingT(t)
247-
res := jsonPath("$.registrant", `{"registrant":5553686208582}`)
248-
Expect(res).To(Equal(5553686208582))
249-
}
250-
251-
func Test_JsonPathMethod_WithWordContainingEe(t *testing.T) {
252-
253-
RegisterTestingT(t)
254-
res := jsonPath("$.registrant", `{"registrant":"ETest"}`)
255-
Expect(res).To(Equal("ETest"))
256-
}
257-
258237
func Test_Identical_ReturnsTrue_WithExactlySameArray(t *testing.T) {
259238
RegisterTestingT(t)
260239
first := [2]string{"q1", "q2"}

0 commit comments

Comments
 (0)