From 3bed1d25872af1d57b906c2f08eb86bdff734fc8 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 9 Aug 2022 19:00:02 -0500 Subject: [PATCH] Alternative approach for PathResource without zipfs specifics --- .../jetty/util/resource/PathResource.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java index 37d8aab5f45..112a65bc110 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java @@ -50,9 +50,6 @@ public class PathResource extends Resource { Path abs = path; - // Boolean to track if Path is a ZipFS based - boolean isZipFs = uri.toASCIIString().startsWith("jar:file:"); - /* Catch situation where the Path class has already normalized * the URI eg. input path "aa./foo.txt" * from an #resolve(String) is normalized away during @@ -63,12 +60,8 @@ public class PathResource extends Resource * * ZipFS has lots of restrictions, you cannot trigger many of the alias behavior * like we can in Windows or OSX. - * - * In this case, a Path.toUri() of a directory will not return a trailing slash on zipfs - * so skip the URI based evaluation, the other tests below (like isSameName) will still validate - * the remaining alias behaviors we have. */ - if (!isZipFs && !URIUtil.equalsIgnoreEncodings(uri, path.toUri())) + if (!URIUtil.equalsIgnoreEncodings(uri, cleanUri(path))) { try { @@ -95,8 +88,7 @@ public class PathResource extends Resource try { - // Skip symlink tests on zipfs (not supported by zipfs) - if (!isZipFs && Files.isSymbolicLink(path)) + if (Files.isSymbolicLink(path)) return path.getParent().resolve(Files.readSymbolicLink(path)); if (Files.exists(path)) @@ -216,10 +208,7 @@ public class PathResource extends Resource try { this.path = Paths.get(uri); - String uriString = uri.toString(); - if (Files.isDirectory(path) && !uriString.endsWith(URIUtil.SLASH)) - uri = URI.create(uriString + URIUtil.SLASH); - this.uri = uri; + this.uri = cleanUri(this.path); this.alias = checkAliasPath(); } catch (FileSystemNotFoundException e) @@ -354,6 +343,15 @@ public class PathResource extends Resource Files.copy(this.path, destination); } + private static URI cleanUri(Path path) + { + String raw = URIUtil.correctFileURI(path.toUri()).toASCIIString(); + + if (Files.isDirectory(path) && !raw.endsWith("/")) + raw += '/'; + return URI.create(raw); + } + @Override public String toString() {