From b593a6cdeffaf085d18ffb2d50db8477d7b0d31d Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 15 Aug 2024 19:55:15 -0400 Subject: [PATCH] fix: properly make paths safe --- DownloadTask.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/DownloadTask.cs b/DownloadTask.cs index bcc0304..a1cf889 100644 --- a/DownloadTask.cs +++ b/DownloadTask.cs @@ -678,9 +678,19 @@ private static string MakePathSafe(string input) { private static string[] GetOutputPaths(IReadOnlyCollection> files) { return files - .Select(file => file[3] ?? Path.Join(file[0], file[1], file[2]!)) - .Where(file => file != null) - .Select(MakePathSafe) + .Select(file => { + var outputPath = file[3]; + if (outputPath != null) { + return MakePathSafe(outputPath); + } + + var group = MakePathSafe(file[0] ?? "_default"); + var option = MakePathSafe(file[1] ?? "_default"); + var gamePath = MakePathSafe(file[2]!); + + return Path.Join(group, option, gamePath); + }) + .Where(file => !string.IsNullOrEmpty(file)) .Cast() .ToArray(); } @@ -700,8 +710,8 @@ async Task DuplicateInner(string dest) { return; } - if (!Path.IsPathRooted(path) || !Path.IsPathRooted(dest)) { - throw new Exception($"{path} or {dest} was not a rooted path"); + if (!Path.IsPathFullyQualified(path) || !Path.IsPathFullyQualified(dest)) { + throw new Exception($"{path} or {dest} was not fully qualified"); } if (!await PathHelper.WaitForDelete(dest)) {