[Patch] PR libgcj/19444 - java.net.URI fixes

Michael Koch konqueror@gmx.de
Sat Jan 15 16:20:00 GMT 2005


Hi list,


I wrote the attached patch to fix PR libgcj/19444. The problem was that
userInfo, host and port where never initialized from the authority.
I wrote some (368) new mauve testcases for java.net.URI. 11 testcases
are still failing after these fixes but it still works better then
before.

Ok to commit to trunk ?


Michael


2005-01-15  Michael Koch  <konqueror@gmx.de>

	PR libgcj/19444
	* java/net/URI.java
	(AUTHORITY_REGEXP): New regexp constant.
	(AUTHORITY_USERINFO_GROUP): New constant.
	(AUTHORITY_HOST_GROUP): Likewise.
	(AUTHORITY_PORT_GROUP): Likewise.
	(port): Changed default value to -1.
	(parseURI): Parse authority part and initialize host,
	port and userInfo.

-------------- next part --------------
Index: java/net/URI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URI.java,v
retrieving revision 1.7
diff -u -r1.7 URI.java
--- java/net/URI.java	17 Oct 2004 08:29:56 -0000	1.7
+++ java/net/URI.java	15 Jan 2005 16:17:36 -0000
@@ -1,5 +1,5 @@
-/* URI.java - An URI class --
-   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+/* URI.java -- An URI class
+   Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -35,6 +35,7 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+
 package java.net;
 
 import java.io.IOException;
@@ -44,7 +45,6 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-
 /**
  * @author Ito Kazumitsu (ito.kazumitsu@hitachi-cable.co.jp)
  * @author Dalibor Topic (robilad@kaffe.org)
@@ -64,6 +64,9 @@
   private static final String URI_REGEXP =
     "^(([^:/?#]+):)?((//([^/?#]*))?([^?#]*)(\\?([^#]*))?)?(#(.*))?";
 
+  private static final String AUTHORITY_REGEXP =
+    "^(([^?#]*)@([^?#]*):([^?#]*))?";
+
   /**
    * Valid characters (taken from rfc2396)
    */
@@ -111,6 +114,11 @@
    * Index of fragment component in parsed URI.
    */
   private static final int FRAGMENT_GROUP = 10;
+  
+  private static final int AUTHORITY_USERINFO_GROUP = 2;
+  private static final int AUTHORITY_HOST_GROUP = 3;
+  private static final int AUTHORITY_PORT_GROUP = 4;
+  
   private transient String scheme;
   private transient String rawSchemeSpecificPart;
   private transient String schemeSpecificPart;
@@ -120,7 +128,7 @@
   private transient String userInfo;
   private transient String rawHost;
   private transient String host;
-  private transient int port;
+  private transient int port = -1;
   private transient String rawPath;
   private transient String path;
   private transient String rawQuery;
@@ -168,6 +176,7 @@
   {
     Pattern pattern = Pattern.compile(URI_REGEXP);
     Matcher matcher = pattern.matcher(str);
+    
     if (matcher.matches())
       {
 	scheme = getURIGroup(matcher, SCHEME_GROUP);
@@ -180,10 +189,40 @@
     else
       throw new URISyntaxException(str, "doesn't match URI regular expression");
 
+    if (rawAuthority != null)
+      {
+	pattern = Pattern.compile(AUTHORITY_REGEXP);
+	matcher = pattern.matcher(rawAuthority);
+
+	if (matcher.matches())
+	  {
+	    rawUserInfo = getURIGroup(matcher, AUTHORITY_USERINFO_GROUP);
+	    rawHost = getURIGroup(matcher, AUTHORITY_HOST_GROUP);
+
+	    String portStr = getURIGroup(matcher, AUTHORITY_PORT_GROUP);
+
+	    if (portStr != null)
+	      try
+		{
+		  port = Integer.parseInt(portStr);
+		}
+	      catch (NumberFormatException e)
+		{
+		  URISyntaxException use = new URISyntaxException(str, "doesn't match URI regular expression");
+		  use.initCause(e);
+		  throw e;
+		}
+	  }
+	else
+	  throw new URISyntaxException(str, "doesn't match URI regular expression");
+      }
+
     // We must eagerly unquote the parts, because this is the only time
     // we may throw an exception.
     schemeSpecificPart = unquote(rawSchemeSpecificPart);
     authority = unquote(rawAuthority);
+    userInfo = unquote(rawUserInfo);
+    host = unquote(rawHost);
     path = unquote(rawPath);
     query = unquote(rawQuery);
     fragment = unquote(rawFragment);


More information about the Java-patches mailing list