[FELIX-4339] Make the use of escape characters deterministic

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1548158 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java b/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
index 3499584..b3a07fb 100644
--- a/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
+++ b/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
@@ -146,6 +146,16 @@
                                    SubstitutionCallback callback)
             throws IllegalArgumentException
     {
+        return unescape(doSubstVars(val, currentKey, cycleMap, configProps, callback));
+    }
+
+    private static String doSubstVars(String val,
+                                   String currentKey,
+                                   Map<String,String> cycleMap,
+                                   Map<String,String> configProps,
+                                   SubstitutionCallback callback)
+            throws IllegalArgumentException
+    {
         if (cycleMap == null)
         {
             cycleMap = new HashMap<String,String>();
@@ -187,7 +197,7 @@
         // return the existing value.
         if ((startDelim < 0) || (stopDelim < 0))
         {
-            return unescape(val);
+            return val;
         }
 
         // At this point, we have found a variable placeholder so
@@ -236,10 +246,7 @@
 
         // Now perform substitution again, since there could still
         // be substitutions to make.
-        val = substVars(val, currentKey, cycleMap, configProps, callback);
-
-        // Remove escape characters preceding {, } and \
-        val = unescape(val);
+        val = doSubstVars(val, currentKey, cycleMap, configProps, callback);
 
         // Return the value.
         return val;
diff --git a/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java b/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java
index 8e5ebf9..7dc21d2 100644
--- a/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java
+++ b/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java
@@ -144,4 +144,17 @@
         assertEquals(map1, map2);
     }
 
+    public void testMultipleEscapes()
+    {
+        LinkedHashMap<String, String> map1 = new LinkedHashMap<String, String>();
+        map1.put("a", "$\\\\{var}");
+        map1.put("abc", "${ab}c");
+        map1.put("ab", "${a}b");
+        InterpolationHelper.performSubstitution(map1);
+
+        assertEquals("$\\{var}", map1.get("a"));
+        assertEquals("$\\{var}b", map1.get("ab"));
+        assertEquals("$\\{var}bc", map1.get("abc"));
+    }
+
 }