diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-05-30 15:39:20 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-05-30 15:39:20 -0500 |
| commit | a77a2d48c22b2287d8ad9125e0f9fa68f45def8b (patch) | |
| tree | e45029a243e1b8dcfd707f8dd90fa99b223eea69 /src | |
| parent | 648ef46c787b0ebc96ae205a8b39b3cf5067dad2 (diff) | |
| download | slskd-a77a2d48c22b2287d8ad9125e0f9fa68f45def8b.tar.gz | |
remove deprecated common extensions
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/CommonExtensions.cs | 28 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 8 | ||||
| -rw-r--r-- | src/slskd/Relay/RelayClient.cs | 2 |
3 files changed, 6 insertions, 32 deletions
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index 4b327a1b..c37c1550 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -410,16 +410,6 @@ namespace slskd } /// <summary> - /// Converts the given path to the local format (normalizes path separators to Path.DirectorySeparatorChar). - /// </summary> - /// <param name="path">The path to convert.</param> - /// <returns>The converted path.</returns> - public static string LocalizePath(this string path) - { - return path.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar); - } - - /// <summary> /// <see cref="Path.GetDirectoryName(string)"/>, but for paths normalized to use backslashes. /// </summary> /// <param name="path"></param> @@ -455,7 +445,7 @@ namespace slskd } // normalize path separators - var localizedRemoteFilename = remoteFilename.LocalizePath(); + var localizedRemoteFilename = FileSafety.LocalizePath(remoteFilename); var parts = localizedRemoteFilename.Split(Path.DirectorySeparatorChar); @@ -471,22 +461,6 @@ namespace slskd } /// <summary> - /// Replaces any path traversal segments in the specified <paramref name="path"/> with the specified - /// <paramref name="replacement"/>. - /// </summary> - /// <param name="path">The path to sanitize.</param> - /// <param name="replacement">The string with which to replace path traversal segments.</param> - /// <returns>The sanitized path.</returns> - public static string ReplacePathTraversalSegments(this string path, string replacement = "_") - { - return string.Join(Path.DirectorySeparatorChar, - path - .LocalizePath() - .Split(Path.DirectorySeparatorChar) - .Select(s => s is "." or ".." ? replacement : s)); - } - - /// <summary> /// Converts a ModelStateDictionary into a human-readable format. /// </summary> /// <param name="dictionary">The ModelStateDictionary to format.</param> diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 8123404e..6600cf76 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -832,22 +832,22 @@ namespace slskd var directories = Directories ?? Enumerable.Empty<string>(); - bool IsBlankPath(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])$"); + bool IsBlankPath(string share) => Regex.IsMatch(FileSafety.LocalizePath(share), @"^(!|-){0,1}(\[.*\])$"); directories?.Where(share => IsBlankPath(share)).ToList() .ForEach(blank => results.Add(new ValidationResult($"Share {blank} does not specify a path"))); - bool IsRootMount(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])/$"); + bool IsRootMount(string share) => Regex.IsMatch(FileSafety.LocalizePath(share), @"^(!|-){0,1}(\[.*\])/$"); directories?.Where(share => IsRootMount(share)).ToList() .ForEach(blank => results.Add(new ValidationResult($"Share {blank} specifies a root mount, which is not supported."))); // starts with '/', 'X:', or '\\' - bool IsAbsolutePath(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])?(\/|[a-zA-Z]:|\\\\).*$"); + bool IsAbsolutePath(string share) => Regex.IsMatch(FileSafety.LocalizePath(share), @"^(!|-){0,1}(\[.*\])?(\/|[a-zA-Z]:|\\\\).*$"); directories?.Where(share => !IsAbsolutePath(share)).ToList() .ForEach(relativePath => results.Add(new ValidationResult($"Share {relativePath} contains a relative path; only absolute paths are supported."))); // contains /./ or /../ or \.\ or \..\ or ..\ or ../ or \.. or /.. // which is resolved by some OS and will cause weird, unintended side effects - bool ContainsTraversalSegments(string share) => Regex.IsMatch(share.LocalizePath(), @"^\.+[\/\\]?|[\/\\]\.+[\/\\]|[\/\\]\.+$"); + bool ContainsTraversalSegments(string share) => Regex.IsMatch(FileSafety.LocalizePath(share), @"^\.+[\/\\]?|[\/\\]\.+[\/\\]|[\/\\]\.+$"); directories?.Where(share => ContainsTraversalSegments(share)).ToList() .ForEach(badPath => results.Add(new ValidationResult($"Share {badPath} contains an unsafe path traversal segment."))); diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs index 974ca71e..5c5f9d38 100644 --- a/src/slskd/Relay/RelayClient.cs +++ b/src/slskd/Relay/RelayClient.cs @@ -484,7 +484,7 @@ namespace slskd.Relay // if the controller is Windows and the agent is Linux or vice versa, we need to translate the filename to the // local OS or we're going to get funny results when we go to write the file - destinationFile = destinationFile.LocalizePath(); + destinationFile = FileSafety.LocalizePath(destinationFile); await Retry.Do(task: async () => { |
