diff --git a/core/templating/template_helpers.go b/core/templating/template_helpers.go index 4fef2ea7a..c67a6a10f 100644 --- a/core/templating/template_helpers.go +++ b/core/templating/template_helpers.go @@ -115,6 +115,16 @@ func jsonPath(query, toMatch string) string { if err != nil { return "" } + + // Jsonpath library converts large int into a string with scientific notion, the following + // reverts that process to avoid mismatching when using the jsonpath result for csv data lookup + floatResult, err := strconv.ParseFloat(result, 64) + // if the string is a float and a whole number + if err == nil && floatResult == float64(int64(floatResult)) { + intResult := int(floatResult) + result = strconv.Itoa(intResult) + } + return result } diff --git a/core/templating/templating_test.go b/core/templating/templating_test.go index 5d26e2e72..8f193c6c9 100644 --- a/core/templating/templating_test.go +++ b/core/templating/templating_test.go @@ -403,6 +403,18 @@ func Test_ApplyTemplate_Request_Body_JsonPath_Unescaped(t *testing.T) { Expect(template).To(Equal("O'Reilly")) } +func Test_ApplyTemplate_Request_Body_Jsonpath_LargeInt(t *testing.T) { + RegisterTestingT(t) + + template, err := ApplyTemplate(&models.RequestDetails{ + Body: `{ "id": 5553686208582 }`, + }, make(map[string]string), `{{ Request.Body 'jsonpath' '$.id' }}`) + + Expect(err).To(BeNil()) + + Expect(template).To(Equal("5553686208582")) +} + func Test_ApplyTemplate_ReplaceStringInQueryParams(t *testing.T) { RegisterTestingT(t)