commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1034102 - in /commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/ test/org/apache/commons/configuration/
Date Thu, 11 Nov 2010 20:28:05 GMT
Author: oheger
Date: Thu Nov 11 20:28:05 2010
New Revision: 1034102

URL: http://svn.apache.org/viewvc?rev=1034102&view=rev
Log:
[CONFIGURATION-428] Do not escape a backslash in the value of an XML element when an XMLConfiguration
is saved.

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertyConverter.java
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertyConverter.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertyConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertyConverter.java?rev=1034102&r1=1034101&r2=1034102&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertyConverter.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertyConverter.java
Thu Nov 11 20:28:05 2010
@@ -589,19 +589,35 @@ public final class PropertyConverter
 
     /**
      * Escapes the delimiters that might be contained in the given string. This
+     * method works like {@link #escapeListDelimiter(String, char)}. In addition,
+     * a single backslash will also be escaped.
+     *
+     * @param s the string with the value
+     * @param delimiter the list delimiter to use
+     * @return the correctly escaped string
+     */
+    public static String escapeDelimiters(String s, char delimiter)
+    {
+        String s1 = StringUtils.replace(s, LIST_ESCAPE, LIST_ESCAPE + LIST_ESCAPE);
+        return escapeListDelimiter(s1, delimiter);
+    }
+
+    /**
+     * Escapes the list delimiter if it is contained in the given string. This
      * method ensures that list delimiter characters that are part of a
      * property's value are correctly escaped when a configuration is saved to a
      * file. Otherwise when loaded again the property will be treated as a list
-     * property. A single backslash will also be escaped.
+     * property.
      *
      * @param s the string with the value
      * @param delimiter the list delimiter to use
-     * @return the correctly esaped string
+     * @return the escaped string
+     * @since 1.7
      */
-    public static String escapeDelimiters(String s, char delimiter)
+    public static String escapeListDelimiter(String s, char delimiter)
     {
-        String s1 = StringUtils.replace(s, LIST_ESCAPE, LIST_ESCAPE + LIST_ESCAPE);
-        return StringUtils.replace(s1, String.valueOf(delimiter), LIST_ESCAPE + delimiter);
+        return StringUtils.replace(s, String.valueOf(delimiter), LIST_ESCAPE
+                + delimiter);
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java?rev=1034102&r1=1034101&r2=1034102&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
Thu Nov 11 20:28:05 2010
@@ -1463,7 +1463,7 @@ public class XMLConfiguration extends Ab
                     String txt = newNode.getValue().toString();
                     if (listDelimiter != 0)
                     {
-                        txt = PropertyConverter.escapeDelimiters(txt, listDelimiter);
+                        txt = PropertyConverter.escapeListDelimiter(txt, listDelimiter);
                     }
                     elem.appendChild(document.createTextNode(txt));
                 }

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertyConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertyConverter.java?rev=1034102&r1=1034101&r2=1034102&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertyConverter.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertyConverter.java
Thu Nov 11 20:28:05 2010
@@ -22,10 +22,10 @@ import java.math.BigDecimal;
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.commons.lang.SystemUtils;
-
 import junit.framework.TestCase;
 
+import org.apache.commons.lang.SystemUtils;
+
 /**
  * Test class for PropertyConverter.
  *
@@ -115,6 +115,16 @@ public class TestPropertyConverter exten
                         .escapeDelimiters("C:\\Temp\\,D:\\Data\\", ','));
     }
 
+    /**
+     * Tests whether only the list delimiter can be escaped.
+     */
+    public void testEscapeListDelimiter()
+    {
+        assertEquals("Wrong escaped list delimiter", "C:\\Temp\\\\,D:\\Data\\",
+                PropertyConverter.escapeListDelimiter("C:\\Temp\\,D:\\Data\\",
+                        ','));
+    }
+
     public void testToIterator()
     {
         int[] array = new int[]{1, 2, 3};
@@ -354,7 +364,7 @@ public class TestPropertyConverter exten
         {
             return;
         }
-        
+
         try
         {
             assertEquals(enumObject, PropertyConverter.toEnum(new Integer(-1), enumClass));

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java?rev=1034102&r1=1034101&r2=1034102&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
Thu Nov 11 20:28:05 2010
@@ -1704,6 +1704,25 @@ public class TestXMLConfiguration extend
         }
     }
 
+    /**
+     * Tests whether a windows path can be saved correctly. This test is related
+     * to CONFIGURATION-428.
+     */
+    public void testSaveWindowsPath() throws ConfigurationException
+    {
+        conf.clear();
+        conf.addProperty("path", "C:\\Temp");
+        StringWriter writer = new StringWriter();
+        conf.save(writer);
+        String content = writer.toString();
+        assertTrue("Path not found: " + content,
+                content.indexOf("<path>C:\\Temp</path>") >= 0);
+        conf.save(testSaveFile);
+        XMLConfiguration conf2 = new XMLConfiguration(testSaveFile);
+        assertEquals("Wrong windows path", "C:\\Temp",
+                conf2.getString("path"));
+    }
+
     private class ReloadThread extends Thread
     {
         FileConfiguration config;



Mime
View raw message