From 16271c5f89dd6b8a5af4690fc2813285ce797dad Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 1 Jun 2026 18:43:16 -0500 Subject: add leading slashes back when SanitizePath and retainRoot = true --- src/slskd/Common/FileSafety.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Common/FileSafety.cs b/src/slskd/Common/FileSafety.cs index 9819209f..5a5d964e 100644 --- a/src/slskd/Common/FileSafety.cs +++ b/src/slskd/Common/FileSafety.cs @@ -309,6 +309,7 @@ public static class FileSafety if (retainRoot) { + // leading slashes are stripped of leading slashes by Split() so we must add them back return new string(sep, leadingSlashCount) + newPath; } @@ -427,6 +428,8 @@ public static class FileSafety return null; } + var leadingSlashCount = path.TakeWhile(c => c == '/' || c == '\\').Count(); + os ??= Compute.OSPlatform(); var sep = os.Value == OSPlatform.Windows ? '\\' : '/'; @@ -445,7 +448,15 @@ public static class FileSafety .Where(s => s is not "") .Select(s => SanitizePathSegment(s, replacement, os)); - return string.Join(sep, segments); + var newPath = string.Join(sep, segments); + + if (retainRoot) + { + // leading slashes are stripped of leading slashes by Split() so we must add them back + return new string(sep, leadingSlashCount) + newPath; + } + + return newPath; } /// -- cgit v1.2.3