This is an automated email from the ASF dual-hosted git repository.
pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 80da0cf NIFI-7496: Regex pattern changed to match dashes in filters.
80da0cf is described below
commit 80da0cf47d4619d89620aea0ab8be762f1dde384
Author: Lehel Boér <[email protected]>
AuthorDate: Mon Feb 8 17:57:29 2021 +0100
NIFI-7496: Regex pattern changed to match dashes in filters.
Signed-off-by: Pierre Villard <[email protected]>
This closes #4811.
---
.../nifi/web/search/query/RegexSearchQueryParser.java | 4 ++--
.../nifi/web/search/query/RegexSearchQueryParserTest.java | 13 +++++++++----
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/search/query/RegexSearchQueryParser.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/search/query/RegexSearchQueryParser.java
index 05c9553..f746cc6 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/search/query/RegexSearchQueryParser.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/search/query/RegexSearchQueryParser.java
@@ -27,7 +27,7 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class RegexSearchQueryParser implements SearchQueryParser {
- private static final String REGEX =
"(?<filter>(\\w+:\\w+\\s+)*(\\w+:\\w+)?)(?<term>.*)";
+ private static final String REGEX =
"(?<filter>(\\w+:[\\w-]+\\s+)*(\\w+:[\\w-]+)?)(?<term>.*)";
private static final String FILTER_TOKEN_SEPARATOR = "\\:";
private static final String FILTER_SEPARATOR = "[\\s]+";
private static final String FILTER_GROUP = "filter";
@@ -40,7 +40,7 @@ public class RegexSearchQueryParser implements
SearchQueryParser {
}
@Override
- public SearchQuery parse(final String searchLiteral, final NiFiUser user,
final ProcessGroup rootGroup, final ProcessGroup activeGroup) {
+ public SearchQuery parse(final String searchLiteral, final NiFiUser user,
final ProcessGroup rootGroup, final ProcessGroup activeGroup) {
final Matcher matcher = pattern.matcher(searchLiteral);
if (matcher.matches()) {
final String term = matcher.group(TERM_GROUP);
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/search/query/RegexSearchQueryParserTest.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/search/query/RegexSearchQueryParserTest.java
index cf8e67d..6e22b56 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/search/query/RegexSearchQueryParserTest.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/search/query/RegexSearchQueryParserTest.java
@@ -18,6 +18,7 @@ package org.apache.nifi.web.search.query;
import org.apache.nifi.authorization.user.NiFiUser;
import org.apache.nifi.groups.ProcessGroup;
+import org.apache.nifi.util.StringUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,7 +48,7 @@ public class RegexSearchQueryParserTest {
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][] {
+ return Arrays.asList(new Object[][]{
{"", "", new String[]{}, new String[]{}},
{"lorem ipsum", "lorem ipsum", new String[]{}, new String[]{}},
{"lorem ipsum ", "lorem ipsum ", new String[]{}, new
String[]{}},
@@ -60,13 +61,17 @@ public class RegexSearchQueryParserTest {
{"a:b lorem ipsum c:d", "lorem ipsum c:d", new String[]{"a"},
new String[]{"b"}},
{"a:b lorem ipsum c:d ", "lorem ipsum c:d ", new
String[]{"a"}, new String[]{"b"}},
{"lorem ipsum a:b", "lorem ipsum a:b", new String[]{}, new
String[]{}},
- {"a:b c:d", "", new String[]{"a", "c"}, new String[]{"b",
"d"}},
- {"a:b c:d ", "", new String[]{"a", "c"}, new String[]{"b",
"d"}},
+ {"a:b c:d", StringUtils.EMPTY, new String[]{"a", "c"}, new
String[]{"b", "d"}},
+ {"a:b c:d ", StringUtils.EMPTY, new String[]{"a", "c"},
new String[]{"b", "d"}},
{"a: lorem ipsum", "a: lorem ipsum", new String[]{}, new
String[]{}},
{":b lorem ipsum", ":b lorem ipsum", new String[]{}, new
String[]{}},
{":b lorem ipsum", ":b lorem ipsum", new String[]{}, new
String[]{}},
{"a:b a:b lorem ipsum", "lorem ipsum", new String[]{"a"}, new
String[]{"b"}},
{"a:b a:c lorem ipsum", "lorem ipsum", new String[]{"a"}, new
String[]{"b"}},
+ {"a:b-c", StringUtils.EMPTY, new String[]{"a"}, new
String[]{"b-c"}},
+ {"a:b-c lorem ipsum", "lorem ipsum", new String[]{"a"}, new
String[]{"b-c"}},
+ {"a:b-c d:e lorem ipsum", "lorem ipsum", new String[]{"a",
"d"}, new String[]{"b-c", "e"}}
+
});
}
@@ -81,7 +86,7 @@ public class RegexSearchQueryParserTest {
// then
Assert.assertEquals(expectedTerm, result.getTerm());
- for(int i = 0; i < expectedFilterNames.length; i++) {
+ for (int i = 0; i < expectedFilterNames.length; i++) {
Assert.assertTrue(result.hasFilter(expectedFilterNames[i]));
Assert.assertEquals(expectedFilterValues[i],
result.getFilter(expectedFilterNames[i]));
}