commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1623873 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/PropertiesConfigurationLayout.java test/java/org/apache/commons/configuration/TestPropertiesConfigurationLayout.java
Date Tue, 09 Sep 2014 19:32:49 GMT
Author: oheger
Date: Tue Sep  9 19:32:49 2014
New Revision: 1623873

URL: http://svn.apache.org/r1623873
Log:
[CONFIGURATION-582] Fixed a StringIndexOutOfBoundsException.

Lines in properties files containing only whitespace are now handled
correctly when extracting comments.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfigurationLayout.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfigurationLayout.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfigurationLayout.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfigurationLayout.java?rev=1623873&r1=1623872&r2=1623873&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfigurationLayout.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfigurationLayout.java
Tue Sep  9 19:32:49 2014
@@ -724,7 +724,7 @@ public class PropertiesConfigurationLayo
      */
     static String stripCommentChar(String s, boolean comment)
     {
-        if (s.length() < 1 || (isCommentLine(s) == comment))
+        if (StringUtils.isBlank(s) || (isCommentLine(s) == comment))
         {
             return s;
         }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfigurationLayout.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfigurationLayout.java?rev=1623873&r1=1623872&r2=1623873&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfigurationLayout.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfigurationLayout.java
Tue Sep  9 19:32:49 2014
@@ -661,6 +661,21 @@ public class TestPropertiesConfiguration
     }
 
     /**
+     * Tests whether a line with whitespace is handled correctly. This is
+     * related to CONFIGURATION-582.
+     */
+    @Test
+    public void testLineWithBlank() throws ConfigurationException
+    {
+        builder.addComment(TEST_COMMENT);
+        builder.addLine(" ");
+        builder.addProperty(TEST_KEY, TEST_VALUE);
+        layout.load(config, builder.getReader());
+        assertEquals("Wrong comment", TEST_COMMENT + CRNORM + " ",
+                layout.getCanonicalComment(TEST_KEY, false));
+    }
+
+    /**
      * Helper method for filling the layout object with some properties.
      */
     private void fillLayout()
@@ -720,6 +735,16 @@ public class TestPropertiesConfiguration
         private int commentCounter;
 
         /**
+         * Adds a line verbatim to the simulated file.
+         *
+         * @param s the content of the line
+         */
+        public void addLine(String s)
+        {
+            buf.append(s).append(CR);
+        }
+
+        /**
          * Adds a property to the simulated file.
          *
          * @param key the property key



Mime
View raw message