API rule regex optimization (#13109)

Co-authored-by: Aaron Chung <aaron_chung@apple.com>
This commit is contained in:
Suresh Kumar Anaparti 2026-06-25 20:48:05 +05:30 committed by GitHub
parent 288f9a9fd7
commit f49ab6b394
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -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() {