Skip to content

Commit 44c6cbd

Browse files
committed
handle regex replace for wordlist
1 parent 97a68a8 commit 44c6cbd

File tree

1 file changed

+36
-0
lines changed
  • libs/utils/src/main/java/com/akto/test_editor

1 file changed

+36
-0
lines changed

libs/utils/src/main/java/com/akto/test_editor/Utils.java

+36
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,13 @@ public static ExecutorSingleOperationResp modifySampleDataUtil(String operationT
878878
String regex = regexInfo.get("regex");
879879
String replaceWith = regexInfo.get("replace_with");
880880
newPayload = Utils.applyRegexModifier(payload, regex, replaceWith);
881+
} else if (key instanceof String && key != "" && ((String) key).contains("regex_replace")) {
882+
Map<String, Map<String, String>> regexReplace = parseStringToMap((String) key);
883+
String payload = rawApi.getRequest().getBody();
884+
Map<String, String> regexInfo = regexReplace.get("regex_replace");
885+
String regex = regexInfo.get("regex");
886+
String replaceWith = regexInfo.get("replace_with");
887+
newPayload = Utils.applyRegexModifier(payload, regex, replaceWith);
881888
} else {
882889
newPayload = key.toString();
883890
}
@@ -938,5 +945,34 @@ public static ExecutorSingleOperationResp modifySampleDataUtil(String operationT
938945

939946
}
940947

948+
public static Map<String, Map<String, String>> parseStringToMap(String mapString) {
949+
950+
mapString = mapString.trim();
951+
if (mapString.startsWith("{") && mapString.endsWith("}")) {
952+
mapString = mapString.substring(1, mapString.length() - 1);
953+
}
954+
955+
Map<String, Map<String, String>> resultMap = new HashMap<>();
956+
String[] entries = mapString.split("=", 2);
957+
958+
String outerKey = entries[0].trim();
959+
String innerMapString = entries[1].trim();
960+
961+
innerMapString = innerMapString.substring(1, innerMapString.length() - 1);
962+
963+
Map<String, String> innerMap = new HashMap<>();
964+
String[] innerEntries = innerMapString.split(", ");
965+
966+
for (String innerEntry : innerEntries) {
967+
String[] innerKeyValue = innerEntry.split("=", 2);
968+
String innerKey = innerKeyValue[0].trim();
969+
String innerValue = innerKeyValue[1].trim();
970+
innerMap.put(innerKey, innerValue);
971+
}
972+
973+
resultMap.put(outerKey, innerMap);
974+
return resultMap;
975+
}
976+
941977

942978
}

0 commit comments

Comments
 (0)