From c8f2345e953d04cf22a333c11a3d1ca5bab3306b Mon Sep 17 00:00:00 2001 From: Gary Spencer Date: Thu, 22 Dec 2005 15:32:03 +0000 Subject: [PATCH] Fixed problem with URL decoding when Unicode characters are present in URL. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2061 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../java/org/alfresco/repo/webdav/WebDAV.java | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/source/java/org/alfresco/repo/webdav/WebDAV.java b/source/java/org/alfresco/repo/webdav/WebDAV.java index fbb3b448a2..64c41cd737 100644 --- a/source/java/org/alfresco/repo/webdav/WebDAV.java +++ b/source/java/org/alfresco/repo/webdav/WebDAV.java @@ -17,7 +17,9 @@ package org.alfresco.repo.webdav; import java.io.Serializable; +import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; @@ -43,7 +45,7 @@ public class WebDAV { // Logging - private static Log logger = LogFactory.getLog("org.alfresco.protocol.webdav"); + private static Log logger = LogFactory.getLog("org.alfresco.webdav.protocol"); // WebDAV XML namespace @@ -335,8 +337,22 @@ public class WebDAV { // Try and get the path - String strPath = request.getPathInfo(); + String strPath = null; + + try { + strPath = URLDecoder.decode( request.getRequestURI(), "UTF-8"); + } + catch (Exception ex) { + } + // Find the servlet path and trim from the request path + + String servletPath = request.getServletPath(); + + int rootPos = strPath.indexOf(servletPath); + if ( rootPos != -1) + strPath = strPath.substring( rootPos); + // If we failed to get the path from the request try and get the path from the servlet path if (strPath == null) @@ -372,7 +388,7 @@ public class WebDAV // Return the path - return decodeURL(strPath); + return strPath; } /** @@ -403,7 +419,27 @@ public class WebDAV urlStr.append(path); } - return urlStr.toString(); + // If the URL is to a collection add a trailing slash + + if ( isCollection && urlStr.charAt( urlStr.length() - 1) != PathSeperatorChar) + urlStr.append( PathSeperator); + + // Encode the URL + + String encUrlStr = null; + + try + { + encUrlStr = URLEncoder.encode( urlStr.toString(), "UTF-8"); + } + catch (UnsupportedEncodingException ex) + { + logger.error(ex); + } + + // Return the encoded URL string + + return encUrlStr; } /**