From 983ec7eb888a8bacacb11156d90653b3006f4e44 Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon (cshannon)" Date: Thu, 7 Sep 2017 07:57:38 -0400 Subject: [PATCH] ARTEMIS-1403 - Fix wildcard matching to always respect delimiters The regular expressions for wildcard matching now properly respects the last delimiter in a pattern and will not match a pattern missing the delimiter by mistake --- .../org/apache/activemq/artemis/core/settings/impl/Match.java | 4 +++- .../apache/activemq/artemis/core/settings/RepositoryTest.java | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/settings/impl/Match.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/settings/impl/Match.java index 940dff38cc..b149b2bdb8 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/settings/impl/Match.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/settings/impl/Match.java @@ -35,6 +35,8 @@ public class Match { private static final String WILDCARD_REPLACEMENT = ".*"; + private static final String WILDCARD_CHILD_REPLACEMENT = "(\\..+)*"; + private static final String DOT = "."; private static final String DOT_REPLACEMENT = "\\."; @@ -59,7 +61,7 @@ public class Match { actMatch = actMatch.replace(Match.WORD_WILDCARD, Match.WORD_WILDCARD_REPLACEMENT); // this one has to be done by last as we are using .* and it could be replaced wrongly - actMatch = actMatch.replace(Match.WILDCARD, Match.WILDCARD_REPLACEMENT); + actMatch = actMatch.replace(Match.WILDCARD, Match.WILDCARD_CHILD_REPLACEMENT); } pattern = Pattern.compile(actMatch); diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/settings/RepositoryTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/settings/RepositoryTest.java index ed272c428e..35f84aeabc 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/settings/RepositoryTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/settings/RepositoryTest.java @@ -59,6 +59,9 @@ public class RepositoryTest extends ActiveMQTestBase { Assert.assertEquals("ab#", repo.getMatch("a.b.c")); Assert.assertEquals("abd#", repo.getMatch("a.b.d.lll")); Assert.assertEquals("root", repo.getMatch("z.z.z.z.z")); + Assert.assertEquals("root", repo.getMatch("a.babc")); + Assert.assertEquals("ab#", repo.getMatch("a.b.dabc")); + Assert.assertEquals("abd#", repo.getMatch("a.b.d")); } @Test