mbenson     2004/04/05 14:26:45

  Modified:    src/main/org/apache/tools/ant/launch Locator.java
  Log:
  Fix the previous change; handle invalid URLs and 1.2 compatibility.
  Submitted by:  Martijn Kruithof, Rainer Noack
  
  Revision  Changes    Path
  1.13      +15 -11    ant/src/main/org/apache/tools/ant/launch/Locator.java
  
  Index: Locator.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/launch/Locator.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Locator.java      2 Apr 2004 20:20:43 -0000       1.12
  +++ Locator.java      5 Apr 2004 21:26:45 -0000       1.13
  @@ -101,21 +101,25 @@
        * @since Ant 1.6
        */
       public static String fromURI(String uri) {
  +        URL url = null;
           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) {
           }
  +        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
               && Character.isLetter(uri.charAt(1)) && uri.lastIndexOf(':') > 
-1) {
               uri = uri.substring(1);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to