From 044813cca26667a742e322eec5164e484853034a Mon Sep 17 00:00:00 2001 From: zznty <94796179+zznty@users.noreply.github.com> Date: Tue, 12 Mar 2024 20:56:23 +0700 Subject: [PATCH] [FIX] Fix resolution of files with special characters for embedded file server --- .../socket/handlers/fileserver/FileServerHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java index 393443cb..1a3f9588 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java @@ -14,6 +14,8 @@ import java.io.RandomAccessFile; import java.net.URI; import java.net.URISyntaxException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Clock; @@ -186,7 +188,7 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr final String path; try { - path = Paths.get(new URI(uri).getPath()).normalize().toString().substring(1); + path = Paths.get(new URI(URLEncoder.encode(uri, StandardCharsets.UTF_8)).getPath()).normalize().toString().substring(1); } catch (URISyntaxException e) { sendError(ctx, BAD_REQUEST); return;