Yes, I feel like a fool.
Again, this time with patch attached.

Sorry about that,

Michael
RCS file: 
/home/cvspublic/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/XMLResponseMethodBase.java,v
retrieving revision 1.5
diff -u -r1.5 XMLResponseMethodBase.java
--- XMLResponseMethodBase.java  2000/12/11 02:06:02     1.5
+++ XMLResponseMethodBase.java  2001/02/01 23:21:55
@@ -365,7 +365,7 @@
         public String getHref() {
             Element href = getFirstElement("DAV:", "href");
             if (href != null) {
-                return DOMUtils.getTextValue(href);
+                return URLDecode(DOMUtils.getTextValue(href));
             } else {
                 return "";
             }
@@ -519,6 +519,69 @@
             }
             return format;
         }
+    }
+
+    /**
+     * Decode and return the specified URL-encoded String. 
+     *
+     * @param str The url-encoded string
+     *
+     * @exception IllegalArgumentException if a '%' character is not followed
+     * by a valid 2-digit hexadecimal number
+     */
+    protected static String URLDecode(String str)
+       throws IllegalArgumentException {
+
+       if (str == null)
+           return (null);
+
+       StringBuffer dec = new StringBuffer();
+       int pos = 0;
+       int len = str.length();
+       dec.ensureCapacity(str.length());
+
+       while (pos < len) {
+           int lookahead;      // Look-ahead position
+
+           // Look ahead to the next URLencoded metacharacter, if any
+           for (lookahead = pos; lookahead < len; lookahead++) {
+               char ch = str.charAt(lookahead);
+               if ((ch == '+') || (ch == '%'))
+                   break;
+           }
+
+           // If there were non-metacharacters, copy them as a block
+           if (lookahead > pos) {
+               dec.append(str.substring(pos, lookahead));
+               pos = lookahead;
+           }
+
+           // Shortcut out if we are at the end of the string
+           if (pos >= len)
+               break;
+
+           // Process the next metacharacter
+           char meta = str.charAt(pos);
+           if (meta == '+') {
+               dec.append(' ');
+               pos++;
+           } else if (meta == '%') {
+               try {
+                   dec.append((char) Integer.parseInt
+                              (str.substring(pos+1, pos+3), 16));
+               } catch (NumberFormatException e) {
+                   throw new IllegalArgumentException
+                       ("Invalid hexadecimal '" + str.substring(pos+1, pos+3)
+                        + " in URLencoded string");
+               } catch (StringIndexOutOfBoundsException e) {
+                   throw new IllegalArgumentException
+                       ("Invalid unescaped '%' in URLcoded string");
+               }
+               pos += 3;
+           }
+       }
+       return (dec.toString());
+
     }
 }
 

Reply via email to