From a1e9b00d2d973795b4fa5599876fc2669a66f176 Mon Sep 17 00:00:00 2001 From: Roger Versluis Date: Sat, 2 Sep 2023 16:04:51 -0600 Subject: [PATCH] Remove illegal characters from the download path. --- server/RdtClient.Service/Helpers/DownloadHelper.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/RdtClient.Service/Helpers/DownloadHelper.cs b/server/RdtClient.Service/Helpers/DownloadHelper.cs index a027180..e894126 100644 --- a/server/RdtClient.Service/Helpers/DownloadHelper.cs +++ b/server/RdtClient.Service/Helpers/DownloadHelper.cs @@ -14,8 +14,10 @@ public static class DownloadHelper return null; } + var directory = RemoveInvalidChars(torrent.RdName); + var uri = new Uri(fileUrl); - var torrentPath = Path.Combine(downloadPath, torrent.RdName); + var torrentPath = Path.Combine(downloadPath, directory); if (!Directory.Exists(torrentPath)) { @@ -26,8 +28,15 @@ public static class DownloadHelper fileName = HttpUtility.UrlDecode(fileName); + fileName = RemoveInvalidChars(fileName); + var filePath = Path.Combine(torrentPath, fileName); return filePath; } + + private static String RemoveInvalidChars(String filename) + { + return String.Concat(filename.Split(Path.GetInvalidFileNameChars())); + } } \ No newline at end of file