Browse Source

Fix the previous change; handle invalid URLs and 1.2 compatibility.

Submitted by:  Martijn Kruithof, Rainer Noack


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276278 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 21 years ago
parent
commit
8195ed0fa7
1 changed files with 15 additions and 11 deletions
  1. +15
    -11
      src/main/org/apache/tools/ant/launch/Locator.java

+ 15
- 11
src/main/org/apache/tools/ant/launch/Locator.java View File

@@ -101,21 +101,25 @@ public final class Locator {
* @since Ant 1.6 * @since Ant 1.6
*/ */
public static String fromURI(String uri) { public static String fromURI(String uri) {
URL url = null;
try { try {
URL url = new URL(uri);
if (!("file".equals(url.getProtocol()))) {
throw new IllegalArgumentException("Can only handle file: URIs");
}
StringBuffer buf = new StringBuffer(url.getHost());
if (buf.length() > 0) {
buf.insert(0, "//");
}
buf.append(url.getPath());
uri = buf.toString();
url = new URL(uri);
} catch (MalformedURLException emYouEarlEx) { } catch (MalformedURLException emYouEarlEx) {
} }
if (url == null || !("file".equals(url.getProtocol()))) {
throw new IllegalArgumentException("Can only handle valid file: URIs");
}
StringBuffer buf = new StringBuffer(url.getHost());
if (buf.length() > 0) {
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
}

String file = url.getFile();
int queryPos = file.indexOf('?');
buf.append((queryPos < 0) ? file : file.substring(0, queryPos));

uri = buf.toString().replace('/', File.separatorChar);


uri = uri.replace('/', File.separatorChar);
if (File.pathSeparatorChar == ';' && uri.startsWith("\\") && uri.length() > 2 if (File.pathSeparatorChar == ';' && uri.startsWith("\\") && uri.length() > 2
&& Character.isLetter(uri.charAt(1)) && uri.lastIndexOf(':') > -1) { && Character.isLetter(uri.charAt(1)) && uri.lastIndexOf(':') > -1) {
uri = uri.substring(1); uri = uri.substring(1);


Loading…
Cancel
Save