Author: oheger
Date: Sat Jun  4 08:54:12 2005
New Revision: 179999

URL: http://svn.apache.org/viewcvs?rev=179999&view=rev
Log:
Fix for issue 35210: perform an additional URL decoding when transforming a URL 
to a File object in ConfigurationUtils

Modified:
    
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
    
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

Modified: 
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java?rev=179999&r1=179998&r2=179999&view=diff
==============================================================================
--- 
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
 (original)
+++ 
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
 Sat Jun  4 08:54:12 2005
@@ -19,6 +19,7 @@
 import java.io.*;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLDecoder;
 import java.util.Iterator;
 
 import org.apache.commons.lang.StringUtils;
@@ -37,6 +38,9 @@
 {
     /** Constant for the file URL protocol.*/
     static final String PROTOCOL_FILE = "file";
+    
+    /** Constant for the URL encoding to be used.*/
+    static final String ENCODING = "UTF-8";
 
     private static Log log = LogFactory.getLog(ConfigurationUtils.class);
 
@@ -471,7 +475,15 @@
     {
         if (PROTOCOL_FILE.equals(url.getProtocol()))
         {
-            return new File(url.getPath());
+            try
+            {
+                return new File(URLDecoder.decode(url.getPath(), ENCODING));
+            }
+            catch (UnsupportedEncodingException uex)
+            {
+                // should normally not happen
+                return null;
+            }
         }
         else
         {

Modified: 
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java?rev=179999&r1=179998&r2=179999&view=diff
==============================================================================
--- 
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
 (original)
+++ 
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
 Sat Jun  4 08:54:12 2005
@@ -304,4 +304,55 @@
             }
         }
     }
+    
+    /**
+     * Tests loading and saving a configuration file with a complicated path
+     * name including spaces. (related to issue 35210)
+     */
+    public void testPathWithSpaces() throws Exception
+    {
+        File path = new File(TARGET_DIR, "path with spaces");
+        File confFile = new File(path, "config-test.properties");
+        PrintWriter out = null;
+
+        try
+        {
+            if (!path.exists())
+            {
+                assertTrue(path.mkdir());
+            }
+            out = new PrintWriter(new FileWriter(confFile));
+            out.println("saved = false");
+            out.close();
+            out = null;
+
+            URL url = new URL(TARGET_DIR.toURL()
+                    + "path%20with%20spaces/config-test.properties");
+            PropertiesConfiguration config = new PropertiesConfiguration(url);
+            config.load();
+            assertFalse(config.getBoolean("saved"));
+
+            config.setProperty("saved", Boolean.TRUE);
+            config.save();
+            config = new PropertiesConfiguration();
+            config.setFile(confFile);
+            config.load();
+            assertTrue(config.getBoolean("saved"));
+        }
+        finally
+        {
+            if (out != null)
+            {
+                out.close();
+            }
+            if (confFile.exists())
+            {
+                assertTrue(confFile.delete());
+            }
+            if (path.exists())
+            {
+                assertTrue(path.delete());
+            }
+        }
+    }
 }

Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?rev=179999&r1=179998&r2=179999&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Sat Jun  4 
08:54:12 2005
@@ -23,6 +23,11 @@
   <body>
 
     <release version="1.2-dev" date="in SVN">
+      <action dev="oheger" type="update" issue="35210">
+        Fixed a problem related to file based configurations that are loaded
+        from a URL which is application/x-www-form-urlencoded: the save() 
method
+        would store such files at a wrong location.
+      </action>
       <action dev="oheger" type="update" issue="34289">
         Updated FileChangedReloadingStrategy to use the file based 
configuration's
         source URL to find the file to watch. Before that it was possible that



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to