Fix #107: Correctly parse placeholder when [BODY] is an array
This commit is contained in:
parent
2a632e8f87
commit
50f530a05c
@ -232,7 +232,7 @@ func sanitizeAndResolve(elements []string, result *Result) ([]string, []string)
|
|||||||
checkingForExistence = true
|
checkingForExistence = true
|
||||||
element = strings.TrimSuffix(strings.TrimPrefix(element, HasFunctionPrefix), FunctionSuffix)
|
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 checkingForExistence {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
element = "false"
|
element = "false"
|
||||||
|
@ -183,6 +183,13 @@ func TestCondition_evaluate(t *testing.T) {
|
|||||||
ExpectedSuccess: false,
|
ExpectedSuccess: false,
|
||||||
ExpectedOutput: "[BODY].user.firstName (john) == [BODY].user.lastName (doe)",
|
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",
|
Name: "body-jsonpath-complex-int",
|
||||||
Condition: Condition("[BODY].data.id == 1"),
|
Condition: Condition("[BODY].data.id == 1"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user