FELIX-3651 escape some characters in bundle location to make valid filters more likely

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1486758 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationSupport.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationSupport.java
index fd64345..309bdee 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationSupport.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationSupport.java
@@ -594,13 +594,23 @@
     {
         String bsn = bundle.getSymbolicName();
         String version = bundle.getVersion().toString();
-        String location = bundle.getLocation();
+        String location = escape(bundle.getLocation());
         String f = String.format(
                 "(|(%1$s=%2$s)(%1$s=%2$s|%3$s)(%1$s=%2$s|%3$s|%4$s)(%1$s=%2$s|%3$s|%4$s|%5$s))", 
                 key, pid, bsn, version, location );
         return f;
     }
     
+    /**
+     * see core spec 3.2.7.  Escape \*() with preceding \
+     * @param value
+     * @return escaped string
+     */
+    static final String escape(String value)
+    {
+        return value.replaceAll( "([\\\\\\*\\(\\)])", "\\\\$1" );
+    }
+    
     
     private interface ChangeCount {
         long getChangeCount( Configuration configuration, boolean fromEvent, long previous );
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/config/ConfigurationSupportTest.java b/scr/src/test/java/org/apache/felix/scr/impl/config/ConfigurationSupportTest.java
new file mode 100644
index 0000000..80b5915
--- /dev/null
+++ b/scr/src/test/java/org/apache/felix/scr/impl/config/ConfigurationSupportTest.java
@@ -0,0 +1,13 @@
+package org.apache.felix.scr.impl.config;
+
+import junit.framework.TestCase;
+
+public class ConfigurationSupportTest extends TestCase
+{
+
+    public void testEscape()
+    {
+        assertEquals("foo \\(&\\)", ConfigurationSupport.escape("foo (&)"));
+    }
+    
+}