From 8c660947578445fca990b3293b4acf701d31bdf5 Mon Sep 17 00:00:00 2001 From: Mikhail Bobrutskov Date: Thu, 24 Oct 2024 12:42:13 +0200 Subject: [PATCH] added an option to disable versioned-path --- .../java/com/wizzardo/http/FileTreeHandler.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/wizzardo/http/FileTreeHandler.java b/src/main/java/com/wizzardo/http/FileTreeHandler.java index 33966a3..b520b25 100644 --- a/src/main/java/com/wizzardo/http/FileTreeHandler.java +++ b/src/main/java/com/wizzardo/http/FileTreeHandler.java @@ -39,6 +39,7 @@ public class FileTreeHandler implement protected String workDirPath; protected File workDir; protected boolean showFolder = true; + protected boolean versionedPath = true; protected final String name; protected RangeResponseHelper rangeResponseHelper = new RangeResponseHelper(); @@ -150,6 +151,11 @@ public FileTreeHandler setShowFolder(boolean showFolder) { return this; } + public FileTreeHandler setVersionedPath(boolean versionedPath) { + this.versionedPath = versionedPath; + return this; + } + protected String getCanonicalPath(File file) { return Unchecked.call(file::getCanonicalPath); } @@ -265,7 +271,12 @@ protected String encodeName(String name) { } protected String decodePath(String path) { - byte[] bytes = VERSION_PATTERN.matcher(path).replaceAll("").getBytes(StandardCharsets.UTF_8); + byte[] bytes; + if (versionedPath) + bytes = VERSION_PATTERN.matcher(path).replaceAll("").getBytes(StandardCharsets.UTF_8); + else + bytes = path.getBytes(StandardCharsets.UTF_8); + int decodedLength = PercentEncoding.decode(bytes, 0, bytes.length, true); return new String(bytes, 0, decodedLength, StandardCharsets.UTF_8); }