From f930687b4a128ab7443e2ec7268464b3b83322db Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Sun, 16 Aug 2020 15:19:53 -0400 Subject: [PATCH] Clean up code for len() function --- core/util.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/util.go b/core/util.go index 96455f3a..3d087e67 100644 --- a/core/util.go +++ b/core/util.go @@ -13,6 +13,9 @@ const ( ResponseTimePlaceHolder = "[RESPONSE_TIME]" BodyPlaceHolder = "[BODY]" + LengthFunctionPrefix = "len(" + FunctionSuffix = ")" + InvalidConditionElementSuffix = "(INVALID)" ) @@ -34,9 +37,9 @@ func sanitizeAndResolve(list []string, result *Result) []string { // if starts with BodyPlaceHolder, then evaluate json path if strings.Contains(element, BodyPlaceHolder) { wantLength := false - if strings.HasPrefix(element, "len(") && strings.HasSuffix(element, ")") { + if strings.HasPrefix(element, LengthFunctionPrefix) && strings.HasSuffix(element, FunctionSuffix) { wantLength = true - element = strings.TrimSuffix(strings.TrimPrefix(element, "len("), ")") + element = strings.TrimSuffix(strings.TrimPrefix(element, LengthFunctionPrefix), FunctionSuffix) } resolvedElement, resolvedElementLength, err := jsonpath.Eval(strings.Replace(element, fmt.Sprintf("%s.", BodyPlaceHolder), "", 1), result.Body) if err != nil {