ib 2004/07/13 06:29:59
Modified: webdavclient/clientlib/src/java/org/apache/webdav/lib
WebdavResource.java
Log:
Make check for self more robust when creating child resources. Take into
account that certain servers (including Slide) escape certain characters that
may but should not be escaped.
Revision Changes Path
1.23 +90 -13
jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java
Index: WebdavResource.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- WebdavResource.java 13 Jul 2004 08:47:30 -0000 1.22
+++ WebdavResource.java 13 Jul 2004 13:29:59 -0000 1.23
@@ -1008,11 +1008,18 @@
String href = response.getHref();
if (!href.startsWith("/"))
href = URIUtil.getPath(href);
+ href = decodeMarks(href);
String httpURLPath = httpURL.getEscapedPath();
- int compared = httpURLPath.compareTo(href);
+ if (httpURLPath.endsWith("/")) {
+ int pathLength = httpURLPath.length();
+ if (pathLength > 1) {
+ httpURLPath = httpURLPath.substring(0, pathLength - 1);
+ }
+ }
// Compare with the href path and requested-path itself.
- if (compared == 0 || compared == -1 && href.endsWith("/") ||
- compared == 1 && httpURLPath.endsWith("/")) {
+ if (httpURLPath.equals(href.endsWith("/") && href.length() > 1
+ ? href.substring(0, href.length() - 1)
+ : href)) {
// Set the status code for this resource.
if (response.getStatusCode() > 0)
setStatusCode(response.getStatusCode());
@@ -1051,14 +1058,13 @@
if (!itself) {
String myURI = httpURL.getEscapedURI();
char[] childURI = (myURI + (myURI.endsWith("/") ? "" : "/")
- + URIUtil.encodePath(getName(href))
- ).toCharArray();
- HttpURL childURL = httpURL instanceof HttpsURL
- ? new HttpsURL(childURI)
+ + URIUtil.getName(href)).toCharArray();
+ HttpURL childURL = httpURL instanceof HttpsURL
+ ? new HttpsURL(childURI)
: new HttpURL(childURI);
- childURL.setRawAuthority(httpURL.getRawAuthority());
- workingResource.setHttpURL( childURL,
- NOACTION, defaultDepth);
+ childURL.setRawUserinfo(httpURL.getRawUser(),
+ httpURL.getRawPassword());
+ workingResource.setHttpURL(childURL, NOACTION, defaultDepth);
workingResource.setExistence(true);
workingResource.setOverwrite(getOverwrite());
}
@@ -5189,5 +5195,76 @@
} catch (URIException e) {
return escapedName;
}
+ }
+
+ /**
+ * Unescape octets for some characters that a server might (but should not)
+ * have escaped. These are: "-", "_", ".", "!", "~", "*", "'", "(", ")"
+ * Look at section 2.3 of RFC 2396.
+ */
+ private static String decodeMarks(String input) {
+ char[] sequence = input.toCharArray();
+ StringBuffer decoded = new StringBuffer(sequence.length);
+ for (int i = 0; i < sequence.length; i++) {
+ if (sequence[i] == '%' && i < sequence.length - 2) {
+ switch (sequence[i + 1]) {
+ case '2':
+ switch (sequence[i + 2]) {
+ case 'd':
+ case 'D':
+ decoded.append('-');
+ i += 2;
+ continue;
+ case 'e':
+ case 'E':
+ decoded.append('.');
+ i += 2;
+ continue;
+ case '1':
+ decoded.append('!');
+ i += 2;
+ continue;
+ case 'a':
+ case 'A':
+ decoded.append('*');
+ i += 2;
+ continue;
+ case '7':
+ decoded.append('\'');
+ i += 2;
+ continue;
+ case '8':
+ decoded.append('(');
+ i += 2;
+ continue;
+ case '9':
+ decoded.append(')');
+ i += 2;
+ continue;
+ }
+ break;
+ case '5':
+ switch (sequence[i + 2]) {
+ case 'f':
+ case 'F':
+ decoded.append('_');
+ i += 2;
+ continue;
+ }
+ break;
+ case '7':
+ switch (sequence[i + 2]) {
+ case 'e':
+ case 'E':
+ decoded.append('~');
+ i += 2;
+ continue;
+ }
+ break;
+ }
+ }
+ decoded.append(sequence[i]);
+ }
+ return decoded.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]