aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-30 15:39:20 -0500
committerJP Dillingham <jp@dillingham.me>2026-05-30 15:39:20 -0500
commita77a2d48c22b2287d8ad9125e0f9fa68f45def8b (patch)
treee45029a243e1b8dcfd707f8dd90fa99b223eea69
parent648ef46c787b0ebc96ae205a8b39b3cf5067dad2 (diff)
downloadslskd-a77a2d48c22b2287d8ad9125e0f9fa68f45def8b.tar.gz
remove deprecated common extensions
-rw-r--r--src/slskd/Common/CommonExtensions.cs28
-rw-r--r--src/slskd/Core/Options.cs8
-rw-r--r--src/slskd/Relay/RelayClient.cs2
-rw-r--r--tests/slskd.Tests.Unit/Common/FileSafety/LocalizePathTests.cs6
4 files changed, 9 insertions, 35 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 () =>
{
diff --git a/tests/slskd.Tests.Unit/Common/FileSafety/LocalizePathTests.cs b/tests/slskd.Tests.Unit/Common/FileSafety/LocalizePathTests.cs
index 2df3e18f..160f2a72 100644
--- a/tests/slskd.Tests.Unit/Common/FileSafety/LocalizePathTests.cs
+++ b/tests/slskd.Tests.Unit/Common/FileSafety/LocalizePathTests.cs
@@ -22,7 +22,7 @@ public partial class FileSafetyTests
[InlineData("", "")]
public void Linux_NormalizesToForwardSlash(string input, string expected)
{
- var result = input.LocalizePath(OSPlatform.Linux);
+ var result = FileSafety.LocalizePath(input, OSPlatform.Linux);
Assert.Equal(expected, result);
}
@@ -42,7 +42,7 @@ public partial class FileSafetyTests
[InlineData("", "")]
public void Windows_NormalizesToBackslash(string input, string expected)
{
- var result = input.LocalizePath(OSPlatform.Windows);
+ var result = FileSafety.LocalizePath(input, OSPlatform.Windows);
Assert.Equal(expected, result);
}
@@ -50,7 +50,7 @@ public partial class FileSafetyTests
[Fact]
public void NullOs_UsesPlatformDefault_DoesNotThrow()
{
- var result = "foo/bar".LocalizePath();
+ var result = FileSafety.LocalizePath("foo/bar");
Assert.False(string.IsNullOrEmpty(result));
}