diff options
author | Mark Wielaard <mark@klomp.org> | 2005-11-17 10:58:46 +0000 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2005-11-17 10:58:46 +0000 |
commit | 5dd12d0fd420911109c6a98bba8c7f77c63fa36e (patch) | |
tree | 08c0f9416e0640b54ea388128cdfb32faaa80685 | |
parent | 2eaf96bab3bae3b4c07103cfbf7bfbf75c6e42b2 (diff) | |
download | classpath-5dd12d0fd420911109c6a98bba8c7f77c63fa36e.tar.gz |
2005-11-17 Andrew Haley <aph@redhat.com>
* gnu/java/net/protocol/file/Connection.java (unquote): New
method.
(connect): Unquote filename.
* gnu/java/net/protocol/jar/Connection.java (get): Likewise.
* java/net/URL.java (URL): If the file part of a spec is absolute,
ignore the file part of its context.
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | gnu/java/net/protocol/file/Connection.java | 51 | ||||
-rw-r--r-- | gnu/java/net/protocol/jar/Connection.java | 4 | ||||
-rw-r--r-- | java/net/URL.java | 12 |
4 files changed, 69 insertions, 8 deletions
@@ -1,3 +1,13 @@ +2005-11-17 Andrew Haley <aph@redhat.com> + + * gnu/java/net/protocol/file/Connection.java (unquote): New + method. + (connect): Unquote filename. + * gnu/java/net/protocol/jar/Connection.java (get): Likewise. + + * java/net/URL.java (URL): If the file part of a spec is absolute, + ignore the file part of its context. + 2005-11-17 Audrius Meskauskas <AudriusA@Bioinformatics.org> * examples/gnu/classpath/examples/CORBA/swing/README.html: diff --git a/gnu/java/net/protocol/file/Connection.java b/gnu/java/net/protocol/file/Connection.java index 52bd04845..8e4a41366 100644 --- a/gnu/java/net/protocol/file/Connection.java +++ b/gnu/java/net/protocol/file/Connection.java @@ -59,6 +59,7 @@ import java.security.Permission; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.net.MalformedURLException; /** * This subclass of java.net.URLConnection models a URLConnection via @@ -125,6 +126,54 @@ public class Connection extends URLConnection } /** + * Unquote "%" + hex quotes characters + * + * @param str The string to unquote or null. + * + * @return The unquoted string or null if str was null. + * + * @exception MalformedURLException If the given string contains invalid + * escape sequences. + * + * Sadly the same as URI.unquote, but there's nothing we can do to + * make it accessible. + * + */ + public static String unquote(String str) throws MalformedURLException + { + if (str == null) + return null; + byte[] buf = new byte[str.length()]; + int pos = 0; + for (int i = 0; i < str.length(); i++) + { + char c = str.charAt(i); + if (c > 127) + throw new MalformedURLException(str + " : Invalid character"); + if (c == '%') + { + if (i + 2 >= str.length()) + throw new MalformedURLException(str + " : Invalid quoted character"); + int hi = Character.digit(str.charAt(++i), 16); + int lo = Character.digit(str.charAt(++i), 16); + if (lo < 0 || hi < 0) + throw new MalformedURLException(str + " : Invalid quoted character"); + buf[pos++] = (byte) (hi * 16 + lo); + } + else + buf[pos++] = (byte) c; + } + try + { + return new String(buf, 0, pos, "utf-8"); + } + catch (java.io.UnsupportedEncodingException x2) + { + throw (Error) new InternalError().initCause(x2); + } + } + + /** * "Connects" to the file by opening it. */ public void connect() throws IOException @@ -134,7 +183,7 @@ public class Connection extends URLConnection return; // If not connected, then file needs to be openned. - file = new File (getURL().getFile()); + file = new File (unquote(getURL().getFile())); if (! file.isDirectory()) { diff --git a/gnu/java/net/protocol/jar/Connection.java b/gnu/java/net/protocol/jar/Connection.java index e85487420..b787f8b9c 100644 --- a/gnu/java/net/protocol/jar/Connection.java +++ b/gnu/java/net/protocol/jar/Connection.java @@ -82,7 +82,9 @@ public final class Connection extends JarURLConnection if ("file".equals (url.getProtocol())) { - File f = new File (url.getFile()); + String fn = url.getFile(); + fn = gnu.java.net.protocol.file.Connection.unquote(fn); + File f = new File (fn); jf = new JarFile (f, true, ZipFile.OPEN_READ); } else diff --git a/java/net/URL.java b/java/net/URL.java index 627dbc391..1d947a0b4 100644 --- a/java/net/URL.java +++ b/java/net/URL.java @@ -408,10 +408,7 @@ public final class URL implements Serializable // The 1.2 doc specifically says these are copied to the new URL. host = context.host; port = context.port; - file = context.file; userInfo = context.userInfo; - if (file == null || file.length() == 0) - file = "/"; authority = context.authority; } } @@ -423,10 +420,13 @@ public final class URL implements Serializable protocol = context.protocol; host = context.host; port = context.port; - file = context.file; userInfo = context.userInfo; - if (file == null || file.length() == 0) - file = "/"; + if (spec.indexOf(":/", 1) < 0) + { + file = context.file; + if (file == null || file.length() == 0) + file = "/"; + } authority = context.authority; } else // Protocol NOT specified in spec. and no context available. |