Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6581238

URL constructor incorrectly parsing the filename

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • None
    • 6u2
    • core-libs
    • x86
    • windows_xp

      OPERATING SYSTEM(S): Tested on Windows

      FULL JDK VERSION(S):
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)

      DESCRIPTION:
      URL(URL, String) gives incorrect relative URL.

      May be separator are not handled properly while parsing the filename

      Testcase output:

      File is C:\tmp\file
      base URL is http:///C:\tmp\file
      result URL is http:////hello//book.gif
      Error: TEST FAILED,Expected result URL ishttp:///C:\tmp\file\hello//book.gif. OR
      http:///C:/tmp/file/hello//book.gif


      Testcase source:

      import java.io.*;
      import java.net.*;
      import sun.net.www.ParseUtil;

      public class URLTest {
      private static void URLTest (String base, String relative) {
      String str;
      try {
      File input = new File(base);
      System.out.println("File is " + input.getAbsolutePath());
      java.net.URL baseURL = new java.net.URL("http", "/", input.getAbsolutePath());
      System.out.println("base URL is " + baseURL);
      java.net.URL absURL = new java.net.URL(baseURL, relative);
      System.out.println("result URL is " + absURL.toString());

      if (absURL.toString().indexOf("C:\\tmp\\file\\hello//book.gif") >= 0) {
      System.out.println("TEST PASSED");
      } else {
      // To check absolute URL on UNIX platforms
      if (absURL.toString().indexOf("C:/tmp/file/hello//book.gif") >= 0) {
      System.out.println("TEST PASSED");
      // System.exit(0);
      } else {
        System.out.println("Error: TEST FAILED,Expected result URL is"+ "http:///C:\\tmp\\file\\hello//book.gif. OR \n"+ "http:///C:/tmp/file/hello//book.gif");
      }
      }
      } catch (MalformedURLException exc) {
      System.out.println("Error: Throws exception:" + exc);
      }
      System.exit(0);
      }

      public static void main(String[] args) {
      URLTest ("C://tmp//file", "hello//book.gif");
      }
      }

            chegar Chris Hegarty
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: