commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1641943 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration2/PropertiesConfiguration.java test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java test/resources/test.properties
Date Wed, 26 Nov 2014 21:22:03 GMT
Author: oheger
Date: Wed Nov 26 21:22:03 2014
New Revision: 1641943

URL: http://svn.apache.org/r1641943
Log:
[CONFIGURATION-564] Properties without a value and separator are now supported.

The regular expression was slightly modified to support property
declarations that do not have a separator. Such keys are now added to the
configuration without a value.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
    commons/proper/configuration/trunk/src/test/resources/test.properties

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java?rev=1641943&r1=1641942&r2=1641943&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
Wed Nov 26 21:22:03 2014
@@ -628,7 +628,7 @@ public class PropertiesConfiguration ext
         private static final Pattern PROPERTY_PATTERN = Pattern
                 .compile("(([\\S&&[^\\\\" + new String(SEPARATORS)
                         + "]]|\\\\.)*)(\\s*(\\s+|[" + new String(SEPARATORS)
-                        + "])\\s*)(.*)");
+                        + "])\\s*)?(.*)");
 
         /** Constant for the index of the group for the key. */
         private static final int IDX_KEY = 1;
@@ -1185,7 +1185,7 @@ public class PropertiesConfiguration ext
         protected String fetchSeparator(String key, Object value)
         {
             return (getGlobalSeparator() != null) ? getGlobalSeparator()
-                    : getCurrentSeparator();
+                    : StringUtils.defaultString(getCurrentSeparator());
         }
     } // class PropertiesWriter
 

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java?rev=1641943&r1=1641942&r2=1641943&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
Wed Nov 26 21:22:03 2014
@@ -142,15 +142,35 @@ public class TestPropertiesConfiguration
     }
 
     /**
-     * Tests that empty properties are treated as the empty string
-     * (rather than as null).
+     * Checks for a property without a value.
+     * 
+     * @param key the key to be checked
+     */
+    private void checkEmpty(String key)
+    {
+        String empty = conf.getString(key);
+        assertNotNull("Property not found: " + key, empty);
+        assertEquals("Wrong value for property " + key, "", empty);
+    }
+
+    /**
+     * Tests that empty properties are treated as the empty string (rather than
+     * as null).
+     */
+    @Test
+    public void testEmpty()
+    {
+        checkEmpty("test.empty");
+    }
+
+    /**
+     * Tests that properties are detected that do not have a separator and a
+     * value.
      */
     @Test
-    public void testEmpty() throws Exception
+    public void testEmptyNoSeparator()
     {
-        String empty = conf.getString("test.empty");
-        assertNotNull(empty);
-        assertEquals("", empty);
+        checkEmpty("test.empty2");
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/test/resources/test.properties
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/test.properties?rev=1641943&r1=1641942&r2=1641943&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/resources/test.properties (original)
+++ commons/proper/configuration/trunk/src/test/resources/test.properties Wed Nov 26 21:22:03
2014
@@ -32,6 +32,7 @@ test.unescape.list-separator = This stri
 test.equals = value=one
 
 test.empty =
+test.empty2
 
 test.mixed.array = a
 test.mixed.array = b, c, d



Mime
View raw message