Allow tilde for user home in path (#2075)

This commit is contained in:
Dave Fisher 2024-11-13 08:14:56 -08:00 committed by GitHub
parent 64917a2879
commit 94b681c514
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -56,7 +56,15 @@ public class ResolverForFilesystem implements ContentResolver {
if (uri.getScheme() != null && !uri.getScheme().isEmpty() && !uri.getScheme().equals("file")) { if (uri.getScheme() != null && !uri.getScheme().isEmpty() && !uri.getScheme().equals("file")) {
return null; return null;
} }
Path pathFromUri = Path.of(uri.getPath());
String rawPath = uri.getPath();
// Expand "~" to the user's home directory if it appears at the start of the path
if (rawPath.startsWith("~")) {
rawPath = System.getProperty("user.home") + rawPath.substring(1);
}
Path pathFromUri = Path.of(rawPath);
if (Files.isReadable(pathFromUri)) { if (Files.isReadable(pathFromUri)) {
return pathFromUri; return pathFromUri;