You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2013/12/04 12:33:30 UTC
svn commit: r1547767 - in /felix/trunk/utils/src:
main/java/org/apache/felix/utils/properties/InterpolationHelper.java
test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java
test/java/org/apache/felix/utils/properties/PropertiesTest.java
Author: gnodet
Date: Wed Dec 4 11:33:30 2013
New Revision: 1547767
URL: http://svn.apache.org/r1547767
Log:
[FELIX-4342] Substitution is dependent on the order of the map
Modified:
felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java
felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
Modified: felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java?rev=1547767&r1=1547766&r2=1547767&view=diff
==============================================================================
--- felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java (original)
+++ felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java Wed Dec 4 11:33:30 2013
@@ -75,10 +75,11 @@ public class InterpolationHelper {
*/
public static void performSubstitution(Map<String,String> properties, SubstitutionCallback callback)
{
+ Map<String, String> org = new HashMap<String, String>(properties);
for (String name : properties.keySet())
{
String value = properties.get(name);
- properties.put(name, substVars(value, name, null, properties, callback));
+ properties.put(name, substVars(value, name, null, org, callback));
}
}
Modified: felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java?rev=1547767&r1=1547766&r2=1547767&view=diff
==============================================================================
--- felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java (original)
+++ felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java Wed Dec 4 11:33:30 2013
@@ -20,6 +20,7 @@ import junit.framework.TestCase;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.LinkedHashMap;
public class InterpolationHelperTest extends TestCase {
@@ -126,4 +127,21 @@ public class InterpolationHelperTest ext
assertEquals("${a}", InterpolationHelper.substVars("$\\{a\\}", "b", null, new Hashtable(), context));
}
+ public void testSubstitutionOrder()
+ {
+ 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);
+
+ LinkedHashMap<String, String> map2 = new LinkedHashMap<String, String>();
+ map2.put("a", "$\\\\{var}");
+ map2.put("ab", "${a}b");
+ map2.put("abc", "${ab}c");
+ InterpolationHelper.performSubstitution(map2);
+
+ assertEquals(map1, map2);
+ }
+
}
Modified: felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java?rev=1547767&r1=1547766&r2=1547767&view=diff
==============================================================================
--- felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java (original)
+++ felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java Wed Dec 4 11:33:30 2013
@@ -22,6 +22,7 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import junit.framework.TestCase;
@@ -121,6 +122,22 @@ public class PropertiesTest extends Test
assertEquals(props1, props2);
}
+ public void testConfigInterpolation() throws IOException
+ {
+ String config = "a=$\\\\\\\\{var}\n" +
+ "ab=${a}b\n" +
+ "abc=${ab}c";
+
+ java.util.Properties props1 = new java.util.Properties();
+ props1.load(new StringReader(config));
+ InterpolationHelper.performSubstitution((Map) props1);
+
+ org.apache.felix.utils.properties.Properties props2 = new org.apache.felix.utils.properties.Properties();
+ props2.load(new StringReader(config));
+
+ assertEquals(props1, props2);
+ }
+
/**
* <p>
* Test getting property.