jericho     01/03/30 18:23:21

  Modified:    src/webdav/client/src/org/apache/webdav/util GenericURI.java
  Log:
  - Fix an parsing error for the http URL.
  
  If the userinfo(userName and password) have the special characters like '#', '?' and 
'/',
  The HttpURL class didn't work ok.   This patch solve the problem with only '#' and 
'?'.
  
  For the '/' character, I'm thinking of using encoding.  It'll be provied later.
  Actually, URI is required to encode itself, following to the meaning-matched region 
of itself.
  
  Bug reported by: Miguel Carvalho <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.13      +19 -47    
jakarta-slide/src/webdav/client/src/org/apache/webdav/util/GenericURI.java
  
  Index: GenericURI.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/GenericURI.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- GenericURI.java   2001/03/30 12:55:41     1.12
  +++ GenericURI.java   2001/03/31 02:23:20     1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/GenericURI.java,v 
1.12 2001/03/30 12:55:41 jericho Exp $
  - * $Revision: 1.12 $
  - * $Date: 2001/03/30 12:55:41 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/GenericURI.java,v 
1.13 2001/03/31 02:23:20 jericho Exp $
  + * $Revision: 1.13 $
  + * $Date: 2001/03/31 02:23:20 $
    *
    * ====================================================================
    *
  @@ -160,7 +160,6 @@
        * Get the URI string.
        */
       public String getURI() {
  -
           return uri;
       }
   
  @@ -174,7 +173,6 @@
        * @param scheme The scheme for this Generic URI.
        */
       protected void setDefaultScheme(String scheme) {
  -
           defaultScheme = scheme.toLowerCase();
       }
   
  @@ -193,7 +191,6 @@
        * @param port the port number to set for this generic URI.
        */
       protected void setDefaultPort(int port) {
  -
           defaultPort = port;
       }
   
  @@ -554,7 +551,6 @@
        * @return the nel_path.
        */
       public String getNetPath() {
  -
           return getNetPath(uri.toString());
       }
   
  @@ -567,13 +563,13 @@
        * @return the net_path.
        */
       public static String getNetPath(String uri) {
  -
           // consider of net_path
           int from = uri.indexOf("//");
           // Ignore the authority part of URI
           int to = uri.length();
  +        // Ignore the '?' mark so to ignore the query.
           // check the fragment
  -        if (uri.indexOf("#") > 0)
  +        if (uri.indexOf("#") > from)
               to = uri.indexOf("#");
           // get only the path.
           uri = (from >= 0) ? uri.substring(from, to) : null;
  @@ -590,7 +586,6 @@
        * @return the abs_path.
        */
       public String getAbsPath() {
  -
           return getAbsPath(uri.toString());
       }
   
  @@ -607,19 +602,18 @@
   
           // consider of net_path
           int at = uri.indexOf("//");
  +        int from = uri.indexOf("/", (at >= 0) ? at + 2 : 0);
           // Ignore the authority part of URI
           int to = uri.length();
           // Ignore the '?' mark so to ignore the query.
           // check the fragment
  -        if (uri.indexOf("#") > 0)
  +        if (uri.indexOf("#") > from)
               to = uri.indexOf("#");
  -        // ignore the 'at' variable as the start point for substring.
  -        int from = uri.indexOf("/", (at >= 0) ? at + 2 : 0);
           // get only the wanted path.
           uri = (from >= 0) ? uri.substring(from, to) : "/";
   
           return uri;
  -    }
  +   }
   
   
       /**
  @@ -644,7 +638,6 @@
        * @return the path.
        */
       public String getPath() {
  -
           return getPath(uri.toString());
       }
   
  @@ -660,16 +653,15 @@
   
           // consider of net_path
           int at = uri.indexOf("//");
  +        int from = uri.indexOf("/", (at >= 0) ? at + 2 : 0);
           // Ignore the authority part of URI
           int to = uri.length();
           // check the query
  -        if (uri.indexOf("?") > 0)
  +        if (uri.indexOf("?") > from)
               to = uri.indexOf("?");
           // check the fragment
  -        if (uri.indexOf("#") > 0 && uri.indexOf("#") < to)
  +        if (uri.indexOf("#") > from && uri.indexOf("#") < to)
               to = uri.indexOf("#");
  -        // ignore the 'at' variable as the start point for substring.
  -        int from = uri.indexOf("/", (at >= 0) ? at + 2 : 0);
           // get only the path.
           uri = (from >= 0) ? uri.substring(from, to) : "/";
   
  @@ -724,7 +716,6 @@
        * @return The resource or collection name string for this generic URI.
        */
       public String getName() {
  -
           return getName(uri);
       }
   
  @@ -779,27 +770,17 @@
   
           int at = uri.indexOf("//");
           // Just ignore the authority part of URI
  +        at = (at > 0) ? uri.indexOf("/", at + 2) : uri.indexOf("/");
           if (at > 0) {
  -            at = uri.indexOf("/", at + 2);
  -        } else {
  -            at = uri.indexOf("/");
  -        }
  -        if (at > 0) {
  -            int from = -1;
               // check the query
  -            if (uri.indexOf("?", at) > 0)
  -                from = uri.indexOf("?") + 1;
  +            int from = (uri.indexOf("?", at) > 0) ? uri.indexOf("?") + 1 : -1;
               int to = uri.length();
               // check the fragment
  -            if (uri.indexOf("#", at) > 0 && uri.indexOf("#", at) < to)
  +            if (uri.indexOf("#", at) > at && uri.indexOf("#", at) < to)
                   to = uri.indexOf("#");
  -            if (from > 0)
  -                return uri.substring(from, to);
  -            else
  -                return null;
  +            return (from > 0) ? uri.substring(from, to) : null;
           } else
               throw new MalformedURLException("Need to have the path part");
  -
       }
   
   
  @@ -831,23 +812,14 @@
   
           int at = uri.indexOf("//");
           // Just ignore the authority part of URI
  +        at = (at > 0) ? uri.indexOf("/", at + 2) : uri.indexOf("/");
           if (at > 0) {
  -            at = uri.indexOf("/", at + 2);
  -        } else {
  -            at = uri.indexOf("/");
  -        }
  -        if (at > 0) {
  -            int from = -1;
               // check the fragment
  -            if (uri.indexOf("#", at) > 0)
  -                from = uri.indexOf("#") + 1;
  -            if (from > 0)
  -                return uri.substring(from);
  -            else
  -                return null;
  +            int from = (uri.indexOf("#", at) > 0) ?
  +                uri.indexOf("#", at) + 1 : -1;
  +            return (from > 0) ? uri.substring(from) : null;
           } else
               throw new MalformedURLException("Need to have the path part");
  -
       }
   
   
  
  
  

Reply via email to