commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1069097 - in /commons/proper/configuration/trunk/src: changes/changes.xml java/org/apache/commons/configuration/HierarchicalINIConfiguration.java test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java
Date Wed, 09 Feb 2011 21:05:00 GMT
Author: oheger
Date: Wed Feb  9 21:05:00 2011
New Revision: 1069097

URL: http://svn.apache.org/viewvc?rev=1069097&view=rev
Log:
[CONFIGURATION-434] Allow comment characters to be part of property values. To be recognized
as a comment character, the character must be preceded by whitespace.

Modified:
    commons/proper/configuration/trunk/src/changes/changes.xml
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalINIConfiguration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java

Modified: commons/proper/configuration/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1069097&r1=1069096&r2=1069097&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/changes/changes.xml (original)
+++ commons/proper/configuration/trunk/src/changes/changes.xml Wed Feb  9 21:05:00 2011
@@ -23,6 +23,13 @@
 
   <body>
     <release version="1.7" date="in SVN" description="">
+      <action dev="oheger" type="fix" issue="CONFIGURATION-434">
+        HierarchicalINIConfiguration now recognizes comment characters in
+        property definitions only if they are preceded by whitespace. Thus
+        comment characters can now be part of the property value. This is for
+        instance required for the definition of file paths which use the
+        semicolon as path separator.
+      </action>
       <action dev="oheger" type="fix" issue="CONFIGURATION-433">
         Minor improvements of the support for indexed properties in
         ConfigurationDynaBean.

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalINIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalINIConfiguration.java?rev=1069097&r1=1069096&r2=1069097&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalINIConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalINIConfiguration.java
Wed Feb  9 21:05:00 2011
@@ -398,6 +398,12 @@ public class HierarchicalINIConfiguratio
      * <pre>
      * 'value' ; comment -&gt; value
      * </pre>
+     * Note that a comment character is only recognized if there is at least one
+     * whitespace character before it. So it can appear in the property value,
+     * e.g.:
+     * <pre>
+     * C:\\Windows;C:\\Windows\\system32
+     * </pre>
      *
      * @param val the value to be parsed
      * @param reader the reader (needed if multiple lines have to be read)
@@ -420,6 +426,7 @@ public class HierarchicalINIConfiguratio
             int i = quoted ? 1 : 0;
 
             StringBuffer result = new StringBuffer();
+            char lastChar = 0;
             while (i < value.length() && !stop)
             {
                 char c = value.charAt(i);
@@ -452,17 +459,18 @@ public class HierarchicalINIConfiguratio
                 }
                 else
                 {
-                    if (!isCommentChar(c))
+                    if (isCommentChar(c) && Character.isWhitespace(lastChar))
                     {
-                        result.append(c);
+                        stop = true;
                     }
                     else
                     {
-                        stop = true;
+                        result.append(c);
                     }
                 }
 
                 i++;
+                lastChar = c;
             }
 
             String v = result.toString();

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java?rev=1069097&r1=1069096&r2=1069097&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java
Wed Feb  9 21:05:00 2011
@@ -684,6 +684,26 @@ public class TestHierarchicalINIConfigur
     }
 
     /**
+     * Tests whether a value which contains a semicolon can be loaded
+     * successfully. This test is related to CONFIGURATION-434.
+     */
+    public void testValueWithSemicolon() throws ConfigurationException
+    {
+        final String path =
+                "C:\\Program Files\\jar\\manage.jar;"
+                        + "C:\\Program Files\\jar\\guiLauncher.jar";
+        final String content =
+                "[Environment]" + LINE_SEPARATOR + "Application Type=any"
+                        + LINE_SEPARATOR + "Class Path=" + path + "  ;comment"
+                        + LINE_SEPARATOR + "Path=" + path
+                        + "\t; another comment";
+        HierarchicalINIConfiguration config = setUpConfig(content);
+        assertEquals("Wrong class path", path,
+                config.getString("Environment.Class Path"));
+        assertEquals("Wrong path", path, config.getString("Environment.Path"));
+    }
+
+    /**
      * A thread class for testing concurrent access to the global section.
      */
     private static class GlobalSectionTestThread extends Thread



Mime
View raw message