mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8224946: jrtfs URI to Path and Path to URI conversions are wrong
Reviewed-by: alanb
This commit is contained in:
parent
3ab3ffd29f
commit
90fb4990ed
6 changed files with 64 additions and 9 deletions
|
@ -190,10 +190,11 @@ public final class JrtFileSystemProvider extends FileSystemProvider {
|
|||
throw new IllegalArgumentException("Fragment component present");
|
||||
}
|
||||
String path = uri.getPath();
|
||||
if (path == null || path.charAt(0) != '/') {
|
||||
if (path == null || path.charAt(0) != '/' || path.contains("..")) {
|
||||
throw new IllegalArgumentException("Invalid path component");
|
||||
}
|
||||
return getTheFileSystem().getPath(path);
|
||||
|
||||
return getTheFileSystem().getPath("/modules" + path);
|
||||
}
|
||||
|
||||
private FileSystem getTheFileSystem() {
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
package jdk.internal.jrtfs;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOError;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
@ -170,7 +171,16 @@ final class JrtPath implements Path {
|
|||
@Override
|
||||
public final URI toUri() {
|
||||
try {
|
||||
return new URI("jrt", toAbsolutePath().path, null);
|
||||
String p = toAbsolutePath().path;
|
||||
if (!p.startsWith("/modules") || p.contains("..")) {
|
||||
throw new IOError(new RuntimeException(p + " cannot be represented as URI"));
|
||||
}
|
||||
|
||||
p = p.substring("/modules".length());
|
||||
if (p.isEmpty()) {
|
||||
p = "/";
|
||||
}
|
||||
return new URI("jrt", p, null);
|
||||
} catch (URISyntaxException ex) {
|
||||
throw new AssertionError(ex);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue