Skip to content

Commit

Permalink
MODE-1823 - Fixed additional problems in WebDAV servlet encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Horia Chiorean authored and rhauch committed Mar 7, 2013
1 parent 2e7e439 commit d63fa54
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
Expand Up @@ -69,7 +69,7 @@ public String encode( String path ) {
ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar); ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar);
OutputStreamWriter writer = null; OutputStreamWriter writer = null;
try { try {
writer = new OutputStreamWriter(buf, "UTF8"); writer = new OutputStreamWriter(buf, "UTF-8");
} catch (Exception e) { } catch (Exception e) {
LOG.error(e, new TextI18n("Error in encode <" + path + ">")); LOG.error(e, new TextI18n("Error in encode <" + path + ">"));
writer = new OutputStreamWriter(buf); writer = new OutputStreamWriter(buf);
Expand Down
Expand Up @@ -154,7 +154,7 @@ protected String getRelativePath( HttpServletRequest request ) {
if ((result == null) || (result.equals(""))) { if ((result == null) || (result.equals(""))) {
result = "/"; result = "/";
} }
return encodedResult(result); return result;
} }


// No, extract the desired path directly from the request // No, extract the desired path directly from the request
Expand All @@ -163,17 +163,9 @@ protected String getRelativePath( HttpServletRequest request ) {
if ((result == null) || (result.equals(""))) { if ((result == null) || (result.equals(""))) {
result = "/"; result = "/";
} }
//always convert to UTF-8 return result;
return encodedResult(result);
} }


private String encodedResult( String result ) {
try {
return new String(result.getBytes(), "UTF-8");
} catch (Exception e){
throw new RuntimeException(e);
}
}


/** /**
* creates the parent path from the given path by removing the last '/' and everything after that * creates the parent path from the given path by removing the last '/' and everything after that
Expand Down
Expand Up @@ -335,7 +335,7 @@ private String parseDestinationHeader( HttpServletRequest req,
} }


// Remove url encoding from destination // Remove url encoding from destination
destinationPath = RequestUtil.URLDecode(destinationPath, "UTF8"); destinationPath = RequestUtil.URLDecode(destinationPath, "UTF-8");


int protocolIndex = destinationPath.indexOf("://"); int protocolIndex = destinationPath.indexOf("://");
if (protocolIndex >= 0) { if (protocolIndex >= 0) {
Expand Down
Expand Up @@ -142,19 +142,25 @@ protected void folderBody( ITransaction transaction,
childrenTemp.append("\">"); childrenTemp.append("\">");
childrenTemp.append("<td>"); childrenTemp.append("<td>");
childrenTemp.append("<a href=\""); childrenTemp.append("<a href=\"");
String requestURL = req.getRequestURL().toString();
childrenTemp.append(requestURL); StringBuffer childURL = req.getRequestURL();
if (!requestURL.endsWith("/")) { if (!(childURL.charAt(childURL.length() - 1) == '/')) {
childrenTemp.append("/"); childURL.append("/");
} }
childrenTemp.append(child);
//we need to URL encode the child, but just the special chars, UTF-8 encoding is done at the end of this method
childURL.append(URL_ENCODER.encode(child));

StoredObject obj = store.getStoredObject(transaction, path + "/" + child); StoredObject obj = store.getStoredObject(transaction, path + "/" + child);
if (obj == null) { if (obj == null) {
LOG.error(new TextI18n("Should not return null for " + path + "/" + child)); LOG.error(new TextI18n("Should not return null for " + path + "/" + child));
} }
if (obj != null && obj.isFolder()) { if (obj != null && obj.isFolder()) {
childrenTemp.append("/"); childURL.append("/");
} }

childrenTemp.append(childURL);

childrenTemp.append("\">"); childrenTemp.append("\">");
childrenTemp.append(child); childrenTemp.append(child);
childrenTemp.append("</a></td>"); childrenTemp.append("</a></td>");
Expand Down

0 comments on commit d63fa54

Please sign in to comment.