Fix #107: Correctly parse placeholder when [BODY] is an array
This commit is contained in:
		| @ -232,7 +232,7 @@ func sanitizeAndResolve(elements []string, result *Result) ([]string, []string) | ||||
| 					checkingForExistence = true | ||||
| 					element = strings.TrimSuffix(strings.TrimPrefix(element, HasFunctionPrefix), FunctionSuffix) | ||||
| 				} | ||||
| 				resolvedElement, resolvedElementLength, err := jsonpath.Eval(strings.TrimPrefix(element, BodyPlaceholder+"."), result.body) | ||||
| 				resolvedElement, resolvedElementLength, err := jsonpath.Eval(strings.TrimPrefix(strings.TrimPrefix(element, BodyPlaceholder), "."), result.body) | ||||
| 				if checkingForExistence { | ||||
| 					if err != nil { | ||||
| 						element = "false" | ||||
|  | ||||
| @ -183,6 +183,13 @@ func TestCondition_evaluate(t *testing.T) { | ||||
| 			ExpectedSuccess: false, | ||||
| 			ExpectedOutput:  "[BODY].user.firstName (john) == [BODY].user.lastName (doe)", | ||||
| 		}, | ||||
| 		{ | ||||
| 			Name:            "body-jsonpath-when-body-is-array", | ||||
| 			Condition:       Condition("[BODY][0].id == 1"), | ||||
| 			Result:          &Result{body: []byte("[{\"id\": 1}, {\"id\": 2}]")}, | ||||
| 			ExpectedSuccess: true, | ||||
| 			ExpectedOutput:  "[BODY][0].id == 1", | ||||
| 		}, | ||||
| 		{ | ||||
| 			Name:            "body-jsonpath-complex-int", | ||||
| 			Condition:       Condition("[BODY].data.id == 1"), | ||||
|  | ||||
		Reference in New Issue
	
	Block a user