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 2018/06/09 20:00:42 UTC

svn commit: r1833250 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration2/XMLConfiguration.java test/java/org/apache/commons/configuration2/TestXMLConfiguration.java test/resources/test.xml

Author: oheger
Date: Sat Jun  9 20:00:41 2018
New Revision: 1833250

URL: http://svn.apache.org/viewvc?rev=1833250&view=rev
Log:
CONFIGURATION-703: Improved handling of xml:space="preserve".

For tags whose value consists only of whitespace this content is now
returned correctly if xml:space is set to "preserve". Thanks to
Pascal Essiembre for the patch.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
    commons/proper/configuration/trunk/src/test/resources/test.xml

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java?rev=1833250&r1=1833249&r2=1833250&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java Sat Jun  9 20:00:41 2018
@@ -630,7 +630,11 @@ public class XMLConfiguration extends Ba
             }
         }
 
-        boolean childrenFlag = hasChildren || attributes.size() > 1;
+        boolean childrenFlag = false;
+        if (hasChildren || trimFlag)
+        {
+            childrenFlag = hasChildren || attributes.size() > 1;
+        }
         String text = determineValue(buffer.toString(), childrenFlag, trimFlag);
         if (text.length() > 0 || (!childrenFlag && level != 0))
         {

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java?rev=1833250&r1=1833249&r2=1833250&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java Sat Jun  9 20:00:41 2018
@@ -1458,7 +1458,10 @@ public class TestXMLConfiguration
     @Test
     public void testPreserveSpaceOnElement()
     {
-        assertEquals("Wrong value", " preserved ", conf.getString("spaceElement"));
+        assertEquals("Wrong value spaceElement",
+                " preserved ", conf.getString("spaceElement"));
+        assertEquals("Wrong value of spaceBlankElement",
+                "   ", conf.getString("spaceBlankElement"));
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/test/resources/test.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/test.xml?rev=1833250&r1=1833249&r2=1833250&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/resources/test.xml (original)
+++ commons/proper/configuration/trunk/src/test/resources/test.xml Sat Jun  9 20:00:41 2018
@@ -40,7 +40,7 @@ And even longer.
     <test>
         <short>8</short>
     </test>
-	
+
 	<!-- list properties -->
 	<list>
 		<item name="one">one</item>
@@ -54,7 +54,7 @@ And even longer.
 			<item>six</item>
 		</sublist>
 	</list>
-    
+
     <!-- Comma delimited lists (work in elements, but not in attributes) -->
     <split>
       <list1>a,b,c</list1>
@@ -82,19 +82,19 @@ And even longer.
 			<item id="4">four</item>
 		</list>
 	</clear>
-    
+
     <!-- Complex property names -->
     <complexNames>
       <my.elem>Name with dot
         <sub.elem>Another dot</sub.elem>
       </my.elem>
     </complexNames>
-    
+
     <!-- An empty element. This should occur in the configuration with an
          empty string as value.
     -->
     <empty/>
-    
+
     <!-- List nodes with attributes -->
     <attrList>
       <a name="x">ABC</a>
@@ -116,4 +116,5 @@ And even longer.
       <testInvalid xml:space="invalid">     Some other text </testInvalid>
     </space>
     <spaceElement xml:space="preserve"> preserved </spaceElement>
+    <spaceBlankElement xml:space="preserve">   </spaceBlankElement>
 </testconfig>