Skip to content

Commit

Permalink
Removed redundant regex
Browse files Browse the repository at this point in the history
  • Loading branch information
rupert-griffin committed Jul 26, 2024
1 parent 44a9f94 commit c0b9ccf
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/emissary/output/filter/AbstractFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ protected void initializeOutputTypes(@Nullable final Configurator config) {
protected void initializeDenylist(final Configurator config) {
Pattern charSet = Pattern.compile("^[\\w*]+[\\w*.]*[\\w*]+$"); // Match if acceptable characters are in correct order
Pattern repeatedPeriods = Pattern.compile("\\.\\."); // Match if any sequential `.` characters
Pattern wordSequenceWithPeriod = Pattern.compile("\\w+(\\.\\w+)?"); // Match if string is made of [A-Z, a-z, 0-9, _] with . delimiter
Pattern wildcardSuffix = Pattern.compile("^\\w+(\\.\\w+)?\\*?$"); // Match if String is word sequence with optional `*` suffix
Pattern viewNameFormat = Pattern.compile("^\\w+(\\.\\w+)?\\*?$"); // Match if String is word sequence with optional `*` suffix

for (String entry : config.findEntriesAsSet("DENYLIST")) {
if (charSet.matcher(entry).matches() && !repeatedPeriods.matcher(entry).matches()) {
Expand All @@ -190,12 +189,13 @@ protected void initializeDenylist(final Configurator config) {
if (viewName.chars().filter(ch -> ch == '.').count() > 0) {
logger.warn("`DENYLIST = {}` viewName `{}` should not contain any `.` characters", entry, viewName);
}

if (wordSequenceWithPeriod.matcher(viewName).matches()) { // DENYLIST = "<type>.<viewName>", DENYLIST = "<1>.<2>.<3>" allowed
this.denylist.add(entry);
} else if (wildcardSuffix.matcher(viewName).matches()) { // DENYLIST = "<type>.<viewName>*", DENYLIST = "<1>.<2>.<3>*" allowed
String strippedEntry = entry.substring(0, entry.length() - 1);
this.wildCardDenylist.add(strippedEntry);
if (viewNameFormat.matcher(viewName).matches()) {
if (viewName.endsWith("*")) {
String strippedEntry = entry.substring(0, entry.length() - 1);
this.wildCardDenylist.add(strippedEntry);
} else {
this.denylist.add(entry);
}
} else {
throw new EmissaryRuntimeException(String.format(
"Invalid filter configuration: `DENYLIST = %s` " +
Expand Down

0 comments on commit c0b9ccf

Please sign in to comment.