
preprocessor.SubstitutionPreprocessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of regex-static-analysis Show documentation
Show all versions of regex-static-analysis Show documentation
A tool to perform static analysis on regexes to determine whether they are vulnerable to ReDoS.
package preprocessor;
import java.util.HashMap;
import java.util.Map;
public abstract class SubstitutionPreprocessor implements Preprocessor {
private HashMap rules;
public abstract String[][] getRuleStrings();
public SubstitutionPreprocessor() {
rules = new HashMap();
}
public String applyRules(String regex) {
for (Map.Entry findReplace : rules.entrySet()) {
String findString = findReplace.getKey();
String replaceString = findReplace.getValue();
regex = regex.replaceAll(findString, replaceString);
}
return regex;
}
protected void addRule(String findString, String replaceString) {
if (rules.containsKey(findString)) {
throw new IllegalArgumentException("Rule for " + findString + " already exists.");
}
rules.put(findString, replaceString);
}
protected void removeRule(String findString) {
rules.remove(findString);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy