
regexcompiler.RegexEscapedSymbol 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 regexcompiler;
public class RegexEscapedSymbol extends RegexSubexpression {
public enum RegexEscapedSymbolType {
CHARACTER,
OCTAL,
UNICODE,
HEX,
CHARACTER_PROPERTY
}
@Override
public SubexpressionType getSubexpressionType() {
return SubexpressionType.ESCAPED_SYMBOL;
}
private final RegexEscapedSymbolType escapedSymbolType;
public RegexEscapedSymbolType getRegexEscapedSymbolType() {
return escapedSymbolType;
}
public RegexEscapedSymbol(String escapedContent, RegexEscapedSymbolType escapedSymbolType, int index) {
super(escapedContent, index);
this.escapedSymbolType = escapedSymbolType;
}
@Override
public String toString() {
switch (escapedSymbolType) {
case CHARACTER:
return "\\" + getSubexpressionContent();
case OCTAL:
return "\\0" + getSubexpressionContent();
case UNICODE:
return "\\u" + getSubexpressionContent();
case HEX:
return "\\x{" + getSubexpressionContent() + "}";
case CHARACTER_PROPERTY:
return "\\p{" + getSubexpressionContent() + "}";
default:
throw new RuntimeException("Unkown RegexEscapedSymbolType");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy