From ee88fb50f571704365bb321c5fcb0bfe859b4944 Mon Sep 17 00:00:00 2001 From: Roger Versluis Date: Sat, 2 Sep 2023 16:05:29 -0600 Subject: [PATCH] Remove illegal characters from the download path. --- server/RdtClient.Service/Helpers/DownloadHelper.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/RdtClient.Service/Helpers/DownloadHelper.cs b/server/RdtClient.Service/Helpers/DownloadHelper.cs index e894126..7b53569 100644 --- a/server/RdtClient.Service/Helpers/DownloadHelper.cs +++ b/server/RdtClient.Service/Helpers/DownloadHelper.cs @@ -14,7 +14,7 @@ public static class DownloadHelper return null; } - var directory = RemoveInvalidChars(torrent.RdName); + var directory = RemoveInvalidPathChars(torrent.RdName); var uri = new Uri(fileUrl); var torrentPath = Path.Combine(downloadPath, directory); @@ -28,14 +28,19 @@ public static class DownloadHelper fileName = HttpUtility.UrlDecode(fileName); - fileName = RemoveInvalidChars(fileName); + fileName = RemoveInvalidFileNameChars(fileName); var filePath = Path.Combine(torrentPath, fileName); return filePath; } - private static String RemoveInvalidChars(String filename) + private static String RemoveInvalidPathChars(String path) + { + return String.Concat(path.Split(Path.GetInvalidPathChars())); + } + + private static String RemoveInvalidFileNameChars(String filename) { return String.Concat(filename.Split(Path.GetInvalidFileNameChars())); }