Need to special case substring matching when there is no wildcard
to simply perform equals() comparison. (FELIX-2473)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@963840 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 e2aa1b2..68815c2 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
@@ -471,6 +471,16 @@
         boolean result = true;
         int len = pieces.size();
 
+        // Special case, if there is only one piece, then
+        // we must perform an equality test.
+        if (len == 1)
+        {
+            return s.equals(pieces.get(0));
+        }
+
+        // Otherwise, check whether the pieces match
+        // the specified string.
+
         int index = 0;
 
 loop:   for (int i = 0; i < len; i++)
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 dea8c91..f604ba5 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
@@ -27,6 +27,16 @@
     {
         List<String> pieces;
 
+        pieces = SimpleFilter.parseSubstring("*");
+        assertTrue("Should match!", SimpleFilter.compareSubstring(pieces, ""));
+
+        pieces = SimpleFilter.parseSubstring("foo");
+        assertFalse("Should not match!", SimpleFilter.compareSubstring(pieces, ""));
+
+        pieces = SimpleFilter.parseSubstring("");
+        assertTrue("Should match!", SimpleFilter.compareSubstring(pieces, ""));
+        assertFalse("Should not match!", SimpleFilter.compareSubstring(pieces, "foo"));
+
         pieces = SimpleFilter.parseSubstring("foo");
         assertTrue("Should match!", SimpleFilter.compareSubstring(pieces, "foo"));
         assertFalse("Should not match!", SimpleFilter.compareSubstring(pieces, "barfoo"));