This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

varioues patches in URL code


Here are four in principle unrelated patches to URL parsing.
Only the second one (don't prepend '/') is definitely a bug fix.

Adding the URL getPath() adds a JDK 1.3 method.  The documentation is
a bit unclear on the difference between getFile and getPath.  It appears
to be whether a query fragment is included.  I.e. given "file:a?b#x"
getPath returns (under JDK 1.3) "a" while getFile returns "a?b".  I'll
check in the following implementation (which differs from the patch)
after I've tested it:

   public String getPath()
   {
     int quest = file.index('?');
     return quest < 0 ? file : file.substring(0, quest);
   }

The second part (going by the ChangeLog) fixes URLs like "file:a".

The third part is just a minor optimization - pass '/' rather than "/".

The forth part may be the most controversial.  It turns off optimization
of "xx/.." and "./".  JDK 1.3 doesn't do it, and I don't think it is
appropriate.  An exception may be for relative URLs that *start* with
"../" or "./".  A glance at the URL RFS suggests maybe these should
be folded, relative to the context URL.  Another reason for doing that
is for the sake of sameFile.  However, that should be handled in
sameFile - which should be re-written anyway, to use URLStreamHandler.
But that's a matter for a different patch.

Comments?
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/
2002-02-20  Per Bothner  <per@bothner.com>

	* java/net/URL.java (getPath):  New JDK 1.3 method.

	* java/net/URLStreamHandler.java (parseURL):
	It is wrong to prepend '/' to the file part of a relative url.

	* java/net/URLStreamHandler.java (parseURL):
	Minor optizations - append '/' rather than "/".

	* java/net/URLStreamHandler.java (parseURL):
	Don't canonicalize "xx/.." or "./" URLs - JDK doesn't.
	We probably should canonicalize for a context-relative url, though.

Index: java/net/URL.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URL.java,v
retrieving revision 1.9
diff -u -r1.9 URL.java
--- URL.java	2001/09/30 07:52:16	1.9
+++ URL.java	2002/02/20 20:14:48
@@ -219,6 +219,11 @@
     return file;
   }
 
+  public String getPath()
+  {
+    return file;
+  }
+
   public String getHost()
   {
     return host;
Index: java/net/URLStreamHandler.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLStreamHandler.java,v
retrieving revision 1.6
diff -u -r1.6 URLStreamHandler.java
--- URLStreamHandler.java	2001/03/19 23:31:14	1.6
+++ URLStreamHandler.java	2002/02/20 20:14:48
@@ -1,6 +1,6 @@
 // URLStreamHandler.java - Superclass of all stream protocol handlers.
 
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -84,36 +84,17 @@
     else if (file == null || file.length() <= 0)
       {
 	// No file context available; just spec for file.
-	file = "/" + spec.substring(start, limit);
+	file = spec.substring(start, limit);
       }
     else if (start < limit)
       {
 	// Context is available, but only override it if there is a new file.
-        // FIXME: unsure to what extent `/` and File.separatorChar
-	//        can mix in URLs.  Ignore File.separatorChar for now.
 	file = file.substring(0, file.lastIndexOf('/'))
-		+ "/" + spec.substring(start, limit);
+		+ '/' + spec.substring(start, limit);
       }
 
     int index;
 
-    // Replace "/./" with "/".  This probably isn't very efficient in
-    // the general case, but it's probably not bad most of the time.
-    while ((index = file.indexOf("/./")) >= 0)
-      file = file.substring(0, index) + file.substring(index + 2);
-
-    // Process "/../" correctly.  This probably isn't very efficient in
-    // the general case, but it's probably not bad most of the time.
-    while ((index = file.indexOf("/../")) >= 0)
-      {
-	// Strip of the previous directory - if it exists.
-	int previous = file.lastIndexOf('/', index - 1);
-	if (previous >= 0)
-	  file = file.substring(0, previous) + file.substring(index + 3);
-	else
-	  break;
-      }
-    
     u.set(u.getProtocol(), host, port, file, u.getRef());
   }
   

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]