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

java.net.URI.relativize doesn't handle escapes properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 7u45
    • core-libs
    • x86_64
    • linux_ubuntu

      FULL PRODUCT VERSION :
      java version "1.7.0_45"
      Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux eos 3.11.0-24-generic #42-Ubuntu SMP Fri Jul 4 21:19:31 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      java.net.URI.relativize fails to relativize two URIs if they only differ in casing within escapes. For example:

      http://www.example.com/%4a/b/a cannot be relativized against http://www.example.com/%4A/b/.

      Although RFC 2396 states in section 6 that "In general, the rules for equivalence and definition of a normal form, if any, are scheme dependent.", this is not consistent with URI's equals method.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile & run this:

      import java.net.URI;

      public class Test {
          public static void main(String[] args){
              URI u = URI.create("http://www.example.com/%4A/b/");
              URI v = URI.create("http://www.example.com/%4a/b/a");
              System.out.println(u.relativize(v));
          }
      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Prints:

      a
      ACTUAL -
      Prints:

      http://www.example.com/%4a/b/a

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class Test {
          public static void main(String[] args){
              URI u = URI.create("http://www.example.com/%4A/b/");
              URI v = URI.create("http://www.example.com/%4a/b/a");
              assert(u.relativize(v).toString().equals("a"));
          }
      }
          

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

      CUSTOMER SUBMITTED WORKAROUND :
      Normalize escapes by hand.

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

              Created:
              Updated: