From fec423393232bc3b9b3a8b40ebeafb489c871e65 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 4 Jun 2026 22:24:26 -0500 Subject: don't strip roots or restore slashes --- src/slskd/Common/FileSafety.cs | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/slskd/Common/FileSafety.cs b/src/slskd/Common/FileSafety.cs index a07de6d1..73dd4b40 100644 --- a/src/slskd/Common/FileSafety.cs +++ b/src/slskd/Common/FileSafety.cs @@ -412,35 +412,26 @@ public static class FileSafety /// /// Sanitizes the specified to make it suitable and safe on the local operating system - /// by converting to the correct slashes, dropping a root (if present), replacing any invalid characters with - /// the specified , and by dropping any path traversal segments. + /// by converting to the correct slashes, replacing any invalid characters with the specified + /// , and by dropping any path traversal segments. /// /// The path. /// The character to substitute for invalid characters. - /// An optional value indicating whether to strip the path's root, if present. /// An optional operating system override, for testing. /// The sanitized path. - public static string SanitizePath(string path, char replacement = '_', bool stripRoot = false, OperatingSystem? os = null) + public static string SanitizePath(string path, char replacement = '_', OperatingSystem? os = null) { if (path is null) { return null; } - var leadingSlashCount = path.TakeWhile(c => c == '/' || c == '\\').Count(); - os ??= Compute.OperatingSystem(); var sep = os.Value == OperatingSystem.Windows ? '\\' : '/'; // flip slashes the correct way path = LocalizePath(path, os); - if (stripRoot) - { - // strip C:\ or //server, if present (regardless of slash variant, etc) - path = StripPathRoot(path, os); - } - // for each segment, drop nulls (created by double slashes), sanitize, and replace traversal strings var segments = path .Split('/', '\\') @@ -449,13 +440,6 @@ public static class FileSafety var newPath = string.Join(sep, segments); - if (!stripRoot) - { - // leading slashes are stripped by Split() so we must add them back, - // unless we intended to strip the root - return new string(sep, leadingSlashCount) + newPath; - } - return newPath; } -- cgit v1.2.3