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

(zipfs) Zip File System Provider returns doubly-encoded Path URIs

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 9
    • 8, 9
    • core-libs
    • b80
    • x86_64
    • linux
    • Verified

    Backports

      Description

        FULL PRODUCT VERSION :
        java version "1.8.0_45"
        Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
        Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Linux hostname 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u1 x86_64 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        Calling toUri() on a Path obtained from a FileSystem created with the Zip File System Provider returns a URI which has been percent-encoded twice. This is easily observed by creating a zip file system from a path containing one or more spaces: The URI obtained from an entry's path will contain "%2520" for each space.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Pass a "jar:" URI containing one or more percent escapes (such as a file: URI corresponding to a Path with one or more spaces) to FileSystems.newFileSystem. For any existing Path in the returned FileSystem, call Path.toUri() and observe the returned value.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The returned URI should be a valid, readable URI, regardless of whether the URI of the zip archive contains any percent-escapes.
        ACTUAL -
        Calling Path.toUri() returns a URI in which the "%" of each escaped octet has itself been encoded as "%25".

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.util.Map;
        import java.util.Collections;
        import java.net.URI;
        import java.io.IOException;
        import java.nio.file.FileSystem;
        import java.nio.file.FileSystems;
        import java.nio.file.Path;
        import java.nio.file.Paths;

        public class JarPathTest {
            public static void main(String[] args)
            throws IOException {

                Path zip = Paths.get(args[0]);

                URI zipURI = URI.create("jar:" + zip.toUri());
                System.out.println(zipURI);

                Map<String, String> env = Collections.emptyMap();

                try (FileSystem fs = FileSystems.newFileSystem(zipURI, env)) {
                    Path root = fs.getPath("/");
                    URI uri = root.toUri();
                    System.out.println(uri);

                    Paths.get(uri);
                }
            }
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        Treat the URI's decoded parts as if they are percent-encoded:

                uri = URI.create(
                    uri.getScheme() + ":" + uri.getSchemeSpecificPart());


        Attachments

          Issue Links

            Activity

              People

                sherman Xueming Shen
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: