This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: [Patch] PR libgcj/19444 - java.net.URI fixes
Am Samstag, 15. Januar 2005 23:00 schrieb Tom Tromey:
> >>>>> "Michael" == Michael Koch <konqueror@gmx.de> writes:
>
> Michael> I wrote the attached patch to fix PR libgcj/19444. The
> Michael> problem was that userInfo, host and port where never
> Michael> initialized from the authority. I wrote some (368) new
> mauve Michael> testcases for java.net.URI. 11 testcases are still
> failing Michael> after these fixes but it still works better then
> before.
>
> Michael> Ok to commit to trunk ?
>
> With the changes Mark suggested, yes. Thanks.
I commited the attached patch now. No ChangeLog entry changes.
Michael
--
Homepage: http://www.worldforge.org/
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 22:19:30 -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,42 @@
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 use;
+ }
+ }
+ 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);