You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by lu...@apache.org on 2005/02/15 11:45:14 UTC

cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/util URLUtil.java

luetzkendorf    2005/02/15 02:45:14

  Modified:    src/webdav/server/org/apache/slide/webdav/util URLUtil.java
  Log:
  Fix to resolve the problem with plus (+) sign in pathes and file names.
  We only en/decode URL pathes and in pathes the plus sign does not stand
  for a space.
  
  Revision  Changes    Path
  1.2       +19 -20    jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/URLUtil.java
  
  Index: URLUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/URLUtil.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- URLUtil.java	2 Aug 2004 16:36:06 -0000	1.1
  +++ URLUtil.java	15 Feb 2005 10:45:14 -0000	1.2
  @@ -55,10 +55,10 @@
       /**
        * Array containing the safe characters set.
        */
  -    protected static BitSet safeCharacters;
  +    private static BitSet safeCharacters;
       
       
  -    protected static final char[] hexadecimal =
  +    private static final char[] hexadecimal =
       {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        'A', 'B', 'C', 'D', 'E', 'F'};
       
  @@ -86,7 +86,10 @@
           safeCharacters.set('.');
           safeCharacters.set('*');
           safeCharacters.set('/');
  -        
  +        safeCharacters.set('+');
  +        safeCharacters.set('@');
  +        safeCharacters.set('$');
  +        safeCharacters.set(',');        
       }
       
       
  @@ -103,6 +106,7 @@
        *
        * @exception IllegalArgumentException if a '%' character is not followed
        * by a valid 2-digit hexadecimal number
  +     * @deprecated
        */
       public static String URLDecode(String str) {
           
  @@ -118,6 +122,7 @@
        * @param enc The encoding to use; if null, the default encoding is used
        * @exception IllegalArgumentException if a '%' character is not followed
        * by a valid 2-digit hexadecimal number
  +     * @deprecated
        */
       public static String URLDecode(String str, String enc) {
           
  @@ -145,7 +150,7 @@
       /**
        * Decode and return the specified URL-encoded byte array.
        *
  -     * @param bytes The url-encoded byte array
  +     * @param bytes The url-encoded byte array of an URL path.
        * @exception IllegalArgumentException if a '%' character is not followed
        * by a valid 2-digit hexadecimal number
        */
  @@ -157,7 +162,7 @@
       /**
        * Decode and return the specified URL-encoded byte array.
        *
  -     * @param bytes The url-encoded byte array
  +     * @param bytes The url-encoded byte array of an URL path.
        * @param enc The encoding to use; if null, the default encoding is used
        * @exception IllegalArgumentException if a '%' character is not followed
        * by a valid 2-digit hexadecimal number
  @@ -176,10 +181,6 @@
                   b = (byte) ((convertHexDigit(bytes[ix++]) << 4)
                               + convertHexDigit(bytes[ix++]));
               }
  -            if (b == '+') {
  -                b = (byte)' ';
  -            }
  -
               bytes[ox++] = b;
           }
           if (enc != null) {
  @@ -208,7 +209,7 @@
   
   
       /**
  -     * URL rewriter.
  +     * URL rewriter for URL paths.
        *
        * @param path Path which has to be rewiten
        */
  @@ -218,7 +219,7 @@
            * Note: This code portion is very similar to URLEncoder.encode.
            * Unfortunately, there is no way to specify to the URLEncoder which
            * characters should be encoded. Here, ' ' should be encoded as "%20"
  -         * and '/' shouldn't be encoded.
  +         * and '/' shouldn't be encoded. '+' should not be encoded in pathes too.
            */
   
           int maxBytesPerChar = 10;
  @@ -234,7 +235,7 @@
           }
   
           for (int i = 0; i < path.length(); i++) {
  -            int c = (int) path.charAt(i);
  +            int c = path.charAt(i);
               if (safeCharacters.get(c)) {
                   rewrittenPath.append((char)c);
               } else {
  @@ -251,8 +252,8 @@
                       // Converting each byte in the buffer
                       byte toEncode = ba[j];
                       rewrittenPath.append('%');
  -                    int low = (int) (toEncode & 0x0f);
  -                    int high = (int) ((toEncode & 0xf0) >> 4);
  +                    int low = (toEncode & 0x0f);
  +                    int high = ((toEncode & 0xf0) >> 4);
                       rewrittenPath.append(hexadecimal[high]);
                       rewrittenPath.append(hexadecimal[low]);
                   }
  @@ -263,8 +264,6 @@
           return rewrittenPath.toString();
   
       }
  -    
  -    
   }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org