mirror of https://github.com/apache/cloudstack.git
API rule regex optimization (#13109)
Co-authored-by: Aaron Chung <aaron_chung@apple.com>
This commit is contained in:
parent
288f9a9fd7
commit
f49ab6b394
|
|
@ -25,16 +25,18 @@ import org.apache.commons.lang3.StringUtils;
|
|||
|
||||
public final class Rule {
|
||||
private final String rule;
|
||||
private final Pattern compiledPattern;
|
||||
private final static Pattern ALLOWED_PATTERN = Pattern.compile("^[a-zA-Z0-9*]+$");
|
||||
|
||||
public Rule(final String rule) {
|
||||
validate(rule);
|
||||
this.rule = rule;
|
||||
this.compiledPattern = Pattern.compile(rule.replace("*", "\\w*"), Pattern.CASE_INSENSITIVE);
|
||||
}
|
||||
|
||||
public boolean matches(final String commandName) {
|
||||
return StringUtils.isNotEmpty(commandName)
|
||||
&& commandName.toLowerCase().matches(rule.toLowerCase().replace("*", "\\w*"));
|
||||
&& compiledPattern.matcher(commandName).matches();
|
||||
}
|
||||
|
||||
public String getRuleString() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue