Skip to content

Commit

Permalink
Fix IllegalArgumentException with non-ascii paths
Browse files Browse the repository at this point in the history
  • Loading branch information
tachyonicClock committed Jun 16, 2024
1 parent 653ccff commit aed7745
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion native/java/org/jpype/pkg/JPypePackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,21 @@ private static URI toURI(Path path)
URI uri = path.toUri();
if (uri.getScheme().equals("jar") && uri.toString().contains("%2520"))
uri = URI.create("jar:" + uri.getRawSchemeSpecificPart().replaceAll("%25", "%"));
return uri;

// `toASCIIString` ensures the URI is URL encoded with only ascii
// characters. This avoids issues in `sun.nio.fs.UnixUriUtils.fromUri` that
// naively uses `uri.getRawPath()` despite the possibility that it contains
// non-ascii characters that will cause errors. By using `toASCIIString` and
// re-wrapping it in a URI object we ensure that the URI is properly
// encoded. See: https://github.com/jpype-project/jpype/issues/1194
try {
return new URI(uri.toASCIIString());
} catch (Exception e) {
// This exception *should* never occur as we are re-encoding a valid URI.
// Throwing a runtime exception avoids java exception handling boilerplate
// for a situation that *should* never occur.
throw new RuntimeException("Failed to encode URI: " + uri, e);
}
}
//</editor-fold>
}

0 comments on commit aed7745

Please sign in to comment.