classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] RFC: prevent URL degeneration - v2b


From: Chris Burdess
Subject: Re: [cp-patches] RFC: prevent URL degeneration - v2b
Date: Mon, 10 Oct 2005 13:56:36 +0100

Mark Wielaard wrote:
I think this is the wrong approach. You are trying to change the URL by
removing slashes, which might change the semantics. The real bug seems
to be that the leading // for the authority (host) part is not added
when there is no or an empty authority and URL.getFile() does return the
separator '/' between URL-authority and URL-path if constructed through
new URL(String), but not when constructed by giving the separate
components to the constructor. But if getFile() returns a file part that
starts with a slash then whether the leading // for the authority part
are given or not is significant.

So maybe the solution is to change the test for when to include the
authority part (plus "//") to:

    if (authority.length() != 0 || file.startsWith("/"))
      {
        sb.append("//").append(authority);
      }

No (note that this is already what happens in java.net.URLStreamHandler.toExternalForm, and it is wrong for most URL schemes). Again, according to RFC 1738:

   A file URL takes the form:

       file://<host>/<path>

   where <host> is the fully qualified domain name of the system on
   which the <path> is accessible, and <path> is a hierarchical
   directory path of the form <directory>/<directory>/.../<name>.

In java.net.URL, the file part is "/" + <path> here. It should therefore be:

Index: gnu/java/net/protocol/file/Handler.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/net/protocol/file/Handler.java,v
retrieving revision 1.19
diff -u -r1.19 Handler.java
--- gnu/java/net/protocol/file/Handler.java 2 Jul 2005 20:32:13 -0000 1.19 +++ gnu/java/net/protocol/file/Handler.java 10 Oct 2005 12:53:47 -0000
@@ -88,4 +88,34 @@

     return new Connection(url);
   }
+
+  /**
+   * This method converts a file URL object into a String.
+   *
+   * @param url The URL object to convert
+   *
+   * @return A string representation of the url
+   */
+  protected String toExternalForm(URL url)
+  {
+    String protocol = url.getProtocol();
+    String authority = url.getAuthority();
+    if (authority == null)
+      authority = "";
+    String file = url.getFile();
+    String ref = url.getRef();
+
+ int size = protocol.length() + authority.length() + file.length() + 24;
+    StringBuffer sb = new StringBuffer(size);
+    sb.append(protocol);
+    sb.append("://");
+    sb.append(authority);
+    sb.append(file);
+
+    if (ref != null)
+      sb.append('#').append(ref);
+
+    return sb.toString();
+  }
+
 } // class Handler

--
Chris Burdess





reply via email to

[Prev in Thread] Current Thread [Next in Thread]