diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-06-01 18:43:16 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-06-01 18:43:16 -0500 |
| commit | 16271c5f89dd6b8a5af4690fc2813285ce797dad (patch) | |
| tree | 2040ae0024efebfc8f4ed81a75ee79ab74cd0ee6 /src | |
| parent | 7239327610f020dcb9028a845709c79a5567869d (diff) | |
| download | slskd-16271c5f89dd6b8a5af4690fc2813285ce797dad.tar.gz | |
add leading slashes back when SanitizePath and retainRoot = true
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/FileSafety.cs | 13 |
1 files changed, 12 insertions, 1 deletions
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; } /// <summary> |
