Skip to content

Commit

Permalink
#1107 fix large int issue for request body templating
Browse files Browse the repository at this point in the history
  • Loading branch information
tommysitu committed Dec 17, 2023
1 parent 15d6ee9 commit 2730ab9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/templating/template_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
12 changes: 12 additions & 0 deletions core/templating/templating_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2730ab9

Please sign in to comment.