You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2014/04/27 19:34:45 UTC
svn commit: r1590424 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java
Author: oheger
Date: Sun Apr 27 17:34:44 2014
New Revision: 1590424
URL: http://svn.apache.org/r1590424
Log:
[CONFIGURATION-567] XMLBeanDeclaration now escapes node names.
When nested properties are processed the name of a child node used to be
directly passed to configurationAt(). This can fail if the node name contains
characters with a special meaning for the expression engine. Now node names
are escaped using the current expression engine.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java?rev=1590424&r1=1590423&r2=1590424&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java Sun Apr 27 17:34:44 2014
@@ -29,6 +29,7 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.ex.ConfigurationRuntimeException;
import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
import org.apache.commons.configuration.tree.NodeHandler;
+import org.apache.commons.lang3.StringUtils;
/**
* <p>
@@ -515,7 +516,7 @@ public class XMLBeanDeclaration implemen
BeanDeclaration createBeanDeclaration(NodeData<?> node)
{
for (HierarchicalConfiguration<?> config : getConfiguration()
- .configurationsAt(node.nodeName()))
+ .configurationsAt(node.escapedNodeName(getConfiguration())))
{
if (node.matchesConfigRootNode(config))
{
@@ -637,6 +638,21 @@ public class XMLBeanDeclaration implemen
}
/**
+ * Returns the unescaped name of the node stored in this data object.
+ * This method handles the case that the node name may contain reserved
+ * characters with a special meaning for the current expression engine.
+ * In this case, the characters affected have to be escaped accordingly.
+ *
+ * @param config the configuration
+ * @return the escaped node name
+ */
+ public String escapedNodeName(HierarchicalConfiguration<?> config)
+ {
+ return config.getExpressionEngine().nodeKey(node,
+ StringUtils.EMPTY, handler);
+ }
+
+ /**
* Returns a list with the children of the wrapped node, again wrapped
* into {@code NodeData} objects.
*
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java?rev=1590424&r1=1590423&r2=1590424&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java Sun Apr 27 17:34:44 2014
@@ -341,6 +341,22 @@ public class TestXMLBeanDeclaration
}
/**
+ * Tests whether reserved characters in the node names of nested bean declarations
+ * are handled correctly. This is related to CONFIGURATION-567.
+ */
+ @Test
+ public void testGetNestedBeanDeclarationsReservedCharacter()
+ {
+ BaseHierarchicalConfiguration config = new BaseHierarchicalConfiguration();
+ String key = KEY + ".address..private";
+ setupBeanDeclaration(config, key, COMPLEX_ATTRIBUTES[0], COMPLEX_VALUES[0]);
+ XMLBeanDeclaration decl = new XMLBeanDeclaration(config, KEY);
+
+ Map<String, Object> nested = decl.getNestedBeanDeclarations();
+ assertTrue("Key not found", nested.containsKey("address.private"));
+ }
+
+ /**
* Tests whether the factory method for creating nested bean declarations
* gets called.
*/
@@ -522,7 +538,7 @@ public class TestXMLBeanDeclaration
* @param names an array with the names of the properties
* @param values an array with the corresponding values
*/
- private static void setupBeanDeclaration(HierarchicalConfiguration config,
+ private static void setupBeanDeclaration(HierarchicalConfiguration<?> config,
String key, String[] names, String[] values)
{
for (int i = 0; i < names.length; i++)