Hi, John, 
Does the following patch make sense to you? I've counted in your 
comments.

protected void
parseURL(URL url, String url_string, int start, int end)
{
  // This method does not throw an exception or return a value.  Thus our
  // strategy when we encounter an error in parsing is to return without
  // doing anything.

  // Bunches of things should be true.  Make sure.
  if (end < start)
    return;
  if ((end - start) < 2)
    return;
  if (start > url_string.length())
    return;
  if (end > url_string.length())
    end = url_string.length(); // This should be safe

  // Turn end into an offset from the end of the string instead of 
  // the beginning
  end = url_string.length() - end;

    // Skip remains of protocol
    url_string = url_string.substring(start);
-         if (!url_string.startsWith("//"))
-             return;
-         url_string = url_string.substring(2);

+    boolean nohost = false; //whether no host part presents
+    String prefix = "/";  //root path prefix of a file: could be "/", and for some 
+windows file: "drive:/"

+    if( ! url.getProtocol().equals("file") ){
+         if (!url_string.startsWith("//"))
+            return;
+        url_string = url_string.substring(2);
+    } else { 
+       // The following special work is for file protocol...
+
+       //normalize the file separator
+       url_string = 
+url_string.replace(System.getProperty("file.separator").charAt(0), '/');
+
+       //deal with the case: file:///d|/dir/dir/file and file:///d%7C/dir/dir/file
+       url_string = url_string.replace('|', ':');
+       int i;
+       if((i = url_string.toUpperCase().indexOf("%7C")) >= 0)
+           url_string = url_string.substring(0, i) + ":" + url_string.substring(i+3);
+
+       if (url_string.startsWith("//"))
+           url_string = url_string.substring(2);  //filter the leading "//"
+
+       // if another "/" encounters, it's end of a null host part or beginning of 
+root path 
+       if (url_string.startsWith("/")){ 
+              nohost = true;
+              url_string = url_string.substring(1);
+        }
+
+       // Check whether it's a windows platform file: drive:/dir/dir/file
+       if(url_string.charAt(1) == ':' && url_string.charAt(2) == '/'){
+             nohost = true;
+             prefix = url_string.substring(0, 3); //assign "drive:/" to prefix
+             url_string = url_string.substring(3);
+        }
+   } // url.getProtocol().equals("file")

  // Declare some variables
  String host = null;
  int port = -1;
  String file = null;
  String anchor = null;

+ if( ! nohost ){
  // Process host and port
  int slash_index = url_string.indexOf("/");
  int colon_index = url_string.indexOf(":");

  if (slash_index > (url_string.length() - end))
    return;
  else if (slash_index == -1)
    slash_index = url_string.length() - end;

  if ((colon_index == -1) || (colon_index > slash_index))
    {
      host = url_string.substring(0, slash_index);
    }
  else
    {
      host = url_string.substring(0, colon_index);
      
      String port_str = url_string.substring(colon_index + 1, slash_index);
      try
        {
          port = Integer.parseInt(port_str);
        }
      catch (NumberFormatException e)
        {
          return;
        }
    }
  if (slash_index < (url_string.length() - 1))
    url_string = url_string.substring(slash_index + 1);
  else
    url_string = "";
+  } // if( ! nohost )

  // Process file and anchor 
  if (end == 0)
    {
-              file = "/" + url_string;
+             file = prefix + url_string;
      anchor = null;
    }
  else
    {
-             file = "/" + url_string.substring(0, url_string.length() - end);
+            file = prefix + url_string.substring(0, url_string.length() - end);

      // Only set anchor if end char is a '#'.  Otherwise assume we're
      // just supposed to stop scanning for some reason
      if (url_string.charAt(url_string.length() - end) == '#')
        anchor = url_string.substring((url_string.length() - end) + 1,
                                      url_string.length());
      else
        anchor = null;
    }
-           if ((file == null) || (file == ""))             <--- file couldn't be null 
or ""
-               file = "/";

  // Now set the values
  setURL(url, url.getProtocol(), host, port, file, anchor); 
}

Regards...
Gansha

-----Original Message-----
From: John Keiser [mailto:[EMAIL PROTECTED]]
Sent: 2001?8?19? 2:11
To: Wu, Gansha
Cc: '[EMAIL PROTECTED]'
Subject: Re: Enhancement to URLStreamHandler


I can see the sense in using the system file separator, too, but *only*
in file: URLs and nothing else.  I don't think http: URLs need or want
it, and there may even be URL types that want to use backslashes for
something else.  This patch does not appear to take these differences
into account.  If this makes sense to you, could you update this patch?

_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to