Modify substring parsing to accept successive '*' characters. (FELIX-3344)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1441056 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java b/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java
index 93591b5..1bd517b 100644
--- a/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java
+++ b/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java
@@ -403,24 +403,23 @@
char c = value.charAt(idx++);
if (!escaped && (c == '*'))
{
- if (wasStar)
+ // If we have successive '*' characters, then we can
+ // effectively collapse them by ignoring succeeding ones.
+ if (!wasStar)
{
- // encountered two successive stars;
- // I assume this is illegal
- throw new IllegalArgumentException("Invalid filter string: " + value);
+ if (ss.length() > 0)
+ {
+ pieces.add(ss.toString()); // accumulate the pieces
+ // between '*' occurrences
+ }
+ ss.setLength(0);
+ // if this is a leading star, then track it
+ if (pieces.isEmpty())
+ {
+ leftstar = true;
+ }
+ wasStar = true;
}
- if (ss.length() > 0)
- {
- pieces.add(ss.toString()); // accumulate the pieces
- // between '*' occurrences
- }
- ss.setLength(0);
- // if this is a leading star, then track it
- if (pieces.isEmpty())
- {
- leftstar = true;
- }
- wasStar = true;
}
else if (!escaped && (c == '\\'))
{
diff --git a/framework/src/test/java/org/apache/felix/framework/capabilityset/SimpleFilterTest.java b/framework/src/test/java/org/apache/felix/framework/capabilityset/SimpleFilterTest.java
index cf82a1d..b498a73 100644
--- a/framework/src/test/java/org/apache/felix/framework/capabilityset/SimpleFilterTest.java
+++ b/framework/src/test/java/org/apache/felix/framework/capabilityset/SimpleFilterTest.java
@@ -79,5 +79,8 @@
pieces = SimpleFilter.parseSubstring("aaaa*aaaa");
assertFalse("Should not match!", SimpleFilter.compareSubstring(pieces, "aaaaaaa"));
+
+ pieces = SimpleFilter.parseSubstring("aaa**aaa");
+ assertTrue("Should match!", SimpleFilter.compareSubstring(pieces, "aaaaaa"));
}
}