Skip to content

Commit

Permalink
fix: properly make paths safe
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Aug 15, 2024
1 parent 9f3e751 commit b593a6c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions DownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,19 @@ private static string MakePathSafe(string input) {

private static string[] GetOutputPaths(IReadOnlyCollection<List<string?>> 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<string>()
.ToArray();
}
Expand All @@ -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)) {
Expand Down

0 comments on commit b593a6c

Please sign in to comment.