-
Bug
-
Resolution: Fixed
-
P3
-
8, 9
-
b80
-
x86_64
-
linux
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8135901 | emb-9 | Xueming Shen | P3 | Resolved | Fixed | team |
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());
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());
- backported by
-
JDK-8135901 (zipfs) Zip File System Provider returns doubly-encoded Path URIs
-
- Resolved
-
- duplicates
-
JDK-8134451 zip-fs creates URIs that cannot be opened
-
- Closed
-
- relates to
-
JDK-8225563 ZipFileSystem Improperly Handling Escaped Characters (e.g. spaces)
-
- Closed
-