Hi,
I liked Marks suggestion but refined it a bit:

The "//" + authority variant is only used if ambiguity would occur, that means
if the file part starts with "//".

2005-10-11  Robert Schuster  <[EMAIL PROTECTED]>

        * java/net/URLStreamHandler.java:
        (toExternalForm): Use "//" + authority format when file part starts
        with two slashes.

This time I carefully tested with mauve. It 'breaks':

FAIL: gnu.testlet.java.net.URL.URLTest: new URL(string) (number 1)
got file:////c:/pub/files/foobar.txt but expected file://c:/pub/files/foobar.txt

FAIL: gnu.testlet.java.net.URL.URLTest: new URL(string) (number 19)
got file:////hpjavant/bgee/foobar.txt but expected 
file://hpjavant/bgee/foobar.txt

FAIL: gnu.testlet.java.net.URL.URLTest: new URL(protocol, host, file) (number 
45)
got file:////hpjavant/bgee/foobar.txt but expected 
file://hpjavant/bgee/foobar.txt

FAIL: gnu.testlet.java.net.URL.URLTest: new URL(protocol, host, file) (number 
53)
got file:////hpjavant/bgee/foobar.txt but expected 
file://hpjavant/bgee/foobar.txt

However I consider these tests wrong because they violate the URL spec.

proto:////p1/p2

is not the same as

proto://p1/p2

Furthermore this is exactly the bug which causes trouble in our XML parser and
since the other implementation contains it too I send Sun a problem report.

I am going to fix these tests afterwards. Obviously they will then fail on
Sun-based VMs until they fix the problem, too.

Comments?

cu
Robert
Index: java/net/URLStreamHandler.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URLStreamHandler.java,v
retrieving revision 1.35
diff -u -r1.35 URLStreamHandler.java
--- java/net/URLStreamHandler.java	2 Oct 2005 22:58:41 -0000	1.35
+++ java/net/URLStreamHandler.java	10 Oct 2005 22:21:48 -0000
@@ -515,12 +515,18 @@
 	sb.append(":");
       }
     
-    if (authority.length() != 0)
-      {
-	sb.append("//").append(authority);
-      }
-
-    sb.append(file);
+    // If we have superfluous leading slashes (that means, at least 2)
+    // we always add the authority component ("//" + host) to
+    // avoid ambiguity. Otherwise we would generate an URL like
+    // proto://home/foo
+    // where we meant: 
+    // host: <empty> - file: //home/foo
+    // but URL spec says it is:
+    // host: home - file: /foo
+    if (authority.length() != 0 || file.startsWith("//") )
+      sb.append("//").append(authority).append(file);
+    else
+      sb.append(file);
 
     if (ref != null)
       sb.append('#').append(ref);
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to