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

URI incorrectly removes path leaf when the relative spec is query only (RFC1808)

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Description

      ADDITIONAL SYSTEM INFORMATION :
      openjdk version "11.0.1" 2018-10-16
      OpenJDK Runtime Environment (build 11.0.1+13-Ubuntu-3ubuntu3.18.10.1)
      OpenJDK 64-Bit Server VM (build 11.0.1+13-Ubuntu-3ubuntu3.18.10.1, mixed mode, sharing)


      A DESCRIPTION OF THE PROBLEM :
      The method URI.resolve(URI uri) does not produce the correct URL if the provided URI describes a relative URI that is only a query.

      A similar issue has been previously reported against java.net.URL as JDK-6519518, whose "Won't fix" resolution was explained as "URI is the preferred class for manipulating URLs. Due to legacy compatibility concerns,
      we cannot make this change to URL".

      I hope that contrary to URL, URI can be fixed

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      This behavior can be seen by using a base URI that includes a filename at the end of its path (i.e. not just a directory) such as that in RFC 1808 section 5.1., and a relative URI that contains only a query, such as "?y" (without the quotes).

      For example, one might want to resolve the relative URI "?baz" against the base URI "http://example.com/foo/bar".

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The following should be printed to standard output:

      http://example.com/foo/bar?baz
      ACTUAL -
      The following is instead printed to standard output:

      http://example.com/foo/?baz

      ---------- BEGIN SOURCE ----------
      import java.net.URI;
      import java.net.URISyntaxException;

      public class URITest {

      public static void main(String[] args) throws URISyntaxException {
      URI u = new URI("http://example.com/foo/bar");
      System.out.println(u.resolve(new URI(null, null, null, "baz", null)));
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      In the specific case demonstrated in the source code, one might work around the issue by retrieving the path from the base URI and setting it on the relative URI before asking the base URI to resolve the relative URI:

      URI u = new URI("http://example.com/foo/bar");
      System.out.println(u.resolve(new URI(null, null, u.getPath(), "baz", null)));

      This may be very cumbersome in some scenarios.

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              chegar Chris Hegarty
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: