All Downloads are FREE. Search and download functionalities are using the official Maven repository.

preprocessor.SubstitutionPreprocessor Maven / Gradle / Ivy

Go to download

A tool to perform static analysis on regexes to determine whether they are vulnerable to ReDoS.

There is a newer version: 1.0.8
Show newest version
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