diff options
author | Warren Levy <warrenl@gcc.gnu.org> | 1999-06-03 22:29:12 +0000 |
---|---|---|
committer | Warren Levy <warrenl@gcc.gnu.org> | 1999-06-03 22:29:12 +0000 |
commit | a259a24846c8f0e0a9f494af773acff7fa1dcaaf (patch) | |
tree | 6cc7b3c8a9f79ac770d95f7a313ebfed94ca7de5 /libjava/java/net/URL.java | |
parent | 4d070fd3cd90ca25dd13e3dc5f2777d478930631 (diff) | |
download | gcc-a259a24846c8f0e0a9f494af773acff7fa1dcaaf.zip gcc-a259a24846c8f0e0a9f494af773acff7fa1dcaaf.tar.gz gcc-a259a24846c8f0e0a9f494af773acff7fa1dcaaf.tar.bz2 |
[multiple changes]
1999-06-02 Warren Levy <warrenl@cygnus.com>
* java/net/URL.java (URL(URL,String)): Initialize port to -1.
Ignore context if spec is an absolute URL. Fix braindead
string comparison.
(hashCode): Use JDK 1.2 style algorithm.
* java/net/URLStreamHandler.java (parseURL): Reimplement to handle
context URL properly.
1999-05-30 Anthony Green <green@cygnus.com>
* java/net/URLStreamHandler.java (parseURL): Parse relative URLs
correctly. Clean up "/../" and "/./" path fragments.
From-SVN: r27334
Diffstat (limited to 'libjava/java/net/URL.java')
-rw-r--r-- | libjava/java/net/URL.java | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/libjava/java/net/URL.java b/libjava/java/net/URL.java index da56f49..b6dc13d 100644 --- a/libjava/java/net/URL.java +++ b/libjava/java/net/URL.java @@ -29,7 +29,7 @@ public final class URL implements Serializable { private String protocol; private String host; - private int port; + private int port = -1; // Initialize for constructor using context. private String file; private String ref; private URLStreamHandler handler; @@ -117,14 +117,22 @@ public final class URL implements Serializable * to the context's file. The optional anchor is not inherited. */ + // If this is an absolute URL, then ignore context completely. + // An absolute URL must have chars prior to "://" but cannot have a colon + // right after the "://". The second colon is for an optional port value + // and implies that the host from the context is used if available. int colon; + if ((colon = spec.indexOf("://", 1)) > 0 && + ! spec.regionMatches(colon, "://:", 0, 4)) + context = null; + int slash; if ((colon = spec.indexOf(':')) > 0 && (colon < (slash = spec.indexOf('/')) || slash < 0)) { // Protocol specified in spec string. protocol = spec.substring(0, colon); - if (context != null && context.protocol == protocol) + if (context != null && context.protocol.equals(protocol)) { // The 1.2 doc specifically says these are copied to the new URL. host = context.host; @@ -222,8 +230,20 @@ public final class URL implements Serializable { // JCL book says this is computed using (only) the hashcodes of the // protocol, host and file fields. Empirical evidence indicates this - // is probably XOR. - return (protocol.hashCode() ^ host.hashCode() ^ file.hashCode()); + // is probably XOR in JDK 1.1. In JDK 1.2 it seems to be a sum including + // the port. + // + // JDK 1.2 online doc infers that host could be null because it + // explicitly states that file cannot be null but is silent on host. + // A simple example with protocol "http" (hashcode 3213448), host null, + // file "/" (hashcode 47) produced a hashcode (3213494) which appeared + // to be the sum of the two hashcodes plus the port. Another example + // using "/index.html" for file bore this out; as well as "#" for file + // (which was reduced to "" with a hashcode of zero). A "" host also + // causes the port number and the two hashcodes to be summed. + + return (protocol.hashCode() + ((host == null) ? 0 : host.hashCode()) + + port + file.hashCode()); } public URLConnection openConnection() throws IOException |