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

URI constructor does not encode path correctly

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      This is more or less a follow up to JDK-8151244 which was resolved as "Not an issue". However, it is, and it also causes to break a documented guaranty: the documentation to URI states: "For any URI u, it is always the case that [...] n all cases,

           new URI(u.getScheme(),
                   u.getUserInfo(), u.getAuthority(),
                   u.getPath(), u.getQuery(),
                   u.getFragment())
           .equals(u)".

      Neglecting the fact, that this particular constructor does not exist, the following code fails (using the EUR sign as mentioned in the documentation):

              URI uri=new URI("https://www.example.com/get%E2%82%AC.html");
              URI newURI=new URI(uri.getScheme(),
                      uri.getAuthority(),
                      uri.getPath(), uri.getQuery(),
                      uri.getFragment());
              assertEquals(uri, newURI);

      If you try to recreate (parts of) the original URI this way, it will be broken afterwards.



      ---------- BEGIN SOURCE ----------
      import static org.junit.Assert.assertEquals;

      import java.net.URI;
      import java.net.URISyntaxException;

      public class Test {
          @Test
          public void testURI() throws URISyntaxException {
              URI uri=new URI("https://www.example.com/get%E2%82%AC.html");
              URI newURI=new URI(uri.getScheme(),
                      uri.getAuthority(),
                      uri.getPath(), uri.getQuery(),
                      uri.getFragment());
              assertEquals(uri, newURI);
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            dfuchs Daniel Fuchs
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: