Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51584
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 31 Jul 2011 16:59:39 +0000 (16:59 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 31 Jul 2011 16:59:39 +0000 (16:59 +0000)
Ensure file paths are encoded/decoded when translated to/from URLs so special characters don't cause issues.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1152593 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/naming/resources/DirContextURLConnection.java
webapps/docs/changelog.xml

index 89e54fe..80d8343 100644 (file)
@@ -22,6 +22,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
 import java.security.Permission;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -153,6 +155,7 @@ public class DirContextURLConnection
                         path = path.substring(contextPath.length());
                     }
                 }
+                path = URLDecoder.decode(path, "UTF-8");
                 object = context.lookup(path);
                 attributes = context.getAttributes(path);
                 if (object instanceof Resource)
@@ -385,7 +388,8 @@ public class DirContextURLConnection
 
         // Reopen resource
         try {
-            resource = (Resource) context.lookup(getURL().getFile());
+            resource = (Resource) context.lookup(
+                    URLDecoder.decode(getURL().getFile(), "UTF-8"));
         } catch (NamingException e) {
             // Ignore
         }
@@ -445,7 +449,8 @@ public class DirContextURLConnection
                     context.list(file.substring(start));
                 while (enumeration.hasMoreElements()) {
                     NameClassPair ncp = enumeration.nextElement();
-                    result.addElement(ncp.getName());
+                    result.addElement(
+                            URLEncoder.encode(ncp.getName(), "UTF-8"));
                 }
             } catch (NamingException e) {
                 // Unexpected exception
index 2ae9e9c..87b800d 100644 (file)
         the current request thread name. Based on a patch from Felix Schumacher.
         (timw)
       </add>
+      <fix>
+        <bug>51584</bug>: Ensure file paths are encoded/decoded when translated
+        to/from URLs when working with resources from a Context so special
+        characters don't cause issues. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">