diff --git a/libs/utils/src/main/java/com/akto/test_editor/Utils.java b/libs/utils/src/main/java/com/akto/test_editor/Utils.java index 26bef4edf1..36cbb9def8 100644 --- a/libs/utils/src/main/java/com/akto/test_editor/Utils.java +++ b/libs/utils/src/main/java/com/akto/test_editor/Utils.java @@ -878,6 +878,13 @@ public static ExecutorSingleOperationResp modifySampleDataUtil(String operationT String regex = regexInfo.get("regex"); String replaceWith = regexInfo.get("replace_with"); newPayload = Utils.applyRegexModifier(payload, regex, replaceWith); + } else if (key instanceof String && key != "" && ((String) key).contains("regex_replace")) { + Map> regexReplace = parseStringToMap((String) key); + String payload = rawApi.getRequest().getBody(); + Map regexInfo = regexReplace.get("regex_replace"); + String regex = regexInfo.get("regex"); + String replaceWith = regexInfo.get("replace_with"); + newPayload = Utils.applyRegexModifier(payload, regex, replaceWith); } else { newPayload = key.toString(); } @@ -938,5 +945,34 @@ public static ExecutorSingleOperationResp modifySampleDataUtil(String operationT } + public static Map> parseStringToMap(String mapString) { + + mapString = mapString.trim(); + if (mapString.startsWith("{") && mapString.endsWith("}")) { + mapString = mapString.substring(1, mapString.length() - 1); + } + + Map> resultMap = new HashMap<>(); + String[] entries = mapString.split("=", 2); + + String outerKey = entries[0].trim(); + String innerMapString = entries[1].trim(); + + innerMapString = innerMapString.substring(1, innerMapString.length() - 1); + + Map innerMap = new HashMap<>(); + String[] innerEntries = innerMapString.split(", "); + + for (String innerEntry : innerEntries) { + String[] innerKeyValue = innerEntry.split("=", 2); + String innerKey = innerKeyValue[0].trim(); + String innerValue = innerKeyValue[1].trim(); + innerMap.put(innerKey, innerValue); + } + + resultMap.put(outerKey, innerMap); + return resultMap; + } + }