From: markt Date: Sun, 31 Jul 2011 16:59:39 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51584 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d9044751cb85d9af440098931ae0a7f00b26b7c4;p=tomcat7.0 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51584 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 --- diff --git a/java/org/apache/naming/resources/DirContextURLConnection.java b/java/org/apache/naming/resources/DirContextURLConnection.java index 89e54fe0d..80d834330 100644 --- a/java/org/apache/naming/resources/DirContextURLConnection.java +++ b/java/org/apache/naming/resources/DirContextURLConnection.java @@ -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 diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 2ae9e9c85..87b800d85 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -95,6 +95,11 @@ the current request thread name. Based on a patch from Felix Schumacher. (timw) + + 51584: 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) +