From c0b9ccf0fb4aab14b986c4ebe468b17671f863ae Mon Sep 17 00:00:00 2001 From: Rupert Griffin Date: Fri, 26 Jul 2024 14:23:57 -0400 Subject: [PATCH] Removed redundant regex --- .../emissary/output/filter/AbstractFilter.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/emissary/output/filter/AbstractFilter.java b/src/main/java/emissary/output/filter/AbstractFilter.java index c7e8b5c08e..a75ddadac1 100755 --- a/src/main/java/emissary/output/filter/AbstractFilter.java +++ b/src/main/java/emissary/output/filter/AbstractFilter.java @@ -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()) { @@ -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 = ".", DENYLIST = "<1>.<2>.<3>" allowed - this.denylist.add(entry); - } else if (wildcardSuffix.matcher(viewName).matches()) { // DENYLIST = ".*", 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` " +