Skip to content

Commit 0e52528

Browse files
committed
do not use Paths.get() for URIs
1 parent 52c9e63 commit 0e52528

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/utils/test/VirtualFileSystemTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,21 @@ public void toAbsolutePath() throws Exception {
188188

189189
@Test
190190
public void parseStringPath() throws Exception {
191-
parseStringPath(VirtualFileSystemTest::parseStringPath);
191+
parsePath(VirtualFileSystemTest::parseStringPath);
192192
}
193193

194194
@Test
195195
public void parseURIPath() throws Exception {
196-
parseStringPath(VirtualFileSystemTest::parseURIPath);
196+
parsePath(VirtualFileSystemTest::parseURIPath);
197197

198198
for (FileSystem fs : new FileSystem[]{rwHostIOVFS, rHostIOVFS, noHostIOVFS}) {
199199
checkException(UnsupportedOperationException.class, () -> fs.parsePath(URI.create("http://testvfs.org")), "only file uri is supported");
200+
checkException(UnsupportedOperationException.class, () -> fs.parsePath(URI.create("http:/" + VFS_MOUNT_POINT + File.separator + "dir1")), "only file uri is supported");
201+
checkException(UnsupportedOperationException.class, () -> fs.parsePath(URI.create("http://" + VFS_MOUNT_POINT + File.separator + "dir1")), "only file uri is supported");
200202
}
201203
}
202204

203-
public void parseStringPath(BiFunction<FileSystem, String, Path> parsePath) throws Exception {
205+
public void parsePath(BiFunction<FileSystem, String, Path> parsePath) throws Exception {
204206
// from VFS
205207
for (FileSystem fs : new FileSystem[]{rwHostIOVFS, rHostIOVFS, noHostIOVFS}) {
206208
// check regular resource dir

graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/VirtualFileSystem.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,9 @@ void extractResources(Path resourcesDirectory) throws IOException {
694694
@Deprecated
695695
public Path parsePath(URI uri) {
696696
if (uri.getScheme().equals("file")) {
697-
Path ret = Paths.get(uri);
697+
// rather do not use Paths.get(URI) as it looks up the file system provider
698+
// by scheme and can use a non default file system provider
699+
Path ret = Paths.get(uri.getPath());
698700
if (!pathIsInVfs(ret)) {
699701
if (delegate != null) {
700702
ret = delegate.parsePath(uri);
@@ -705,14 +707,17 @@ public Path parsePath(URI uri) {
705707
finest("VFS.parsePath '%s' -> '%s'", uri, ret);
706708
return ret;
707709
} else {
708-
finer("VFS.parsePath: Not supported yet '%s'", uri);
709-
throw new UnsupportedOperationException("Not supported yet.");
710+
String msg = "Unsupported URI scheme '%s'";
711+
finer(msg, uri.getScheme());
712+
throw new UnsupportedOperationException(String.format(msg, uri.getScheme()));
710713
}
711714
}
712715

713716
@Override
714717
@Deprecated
715718
public Path parsePath(String path) {
719+
// It's safe to use the Paths.get(String)
720+
// as it always uses the default file system.
716721
Path p = Paths.get(path);
717722
if (!pathIsInVfs(p)) {
718723
if (delegate != null) {

0 commit comments

Comments
 (0)