aboutsummaryrefslogtreecommitdiffstats
path: root/tests/slskd.Tests.Unit/Common/FileSafety/SanitizePathTests.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-06-04 22:52:37 -0500
committerJP Dillingham <jp@dillingham.me>2026-06-04 22:52:37 -0500
commitee41b93605a380480a5f7d826e7ae0602cd52de1 (patch)
tree65ffc45abf0b9176107ea433993ccc20ad10923a /tests/slskd.Tests.Unit/Common/FileSafety/SanitizePathTests.cs
parent1c14f93ec53559bb9de11fa3d25a2f8a0cc6e686 (diff)
downloadslskd-ee41b93605a380480a5f7d826e7ae0602cd52de1.tar.gz
wip
Diffstat (limited to 'tests/slskd.Tests.Unit/Common/FileSafety/SanitizePathTests.cs')
-rw-r--r--tests/slskd.Tests.Unit/Common/FileSafety/SanitizePathTests.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/slskd.Tests.Unit/Common/FileSafety/SanitizePathTests.cs b/tests/slskd.Tests.Unit/Common/FileSafety/SanitizePathTests.cs
index 12ebdefa..61233e44 100644
--- a/tests/slskd.Tests.Unit/Common/FileSafety/SanitizePathTests.cs
+++ b/tests/slskd.Tests.Unit/Common/FileSafety/SanitizePathTests.cs
@@ -129,5 +129,41 @@ public partial class FileSafetyTests
Assert.False(result.StartsWith('/') || result.StartsWith('\\'));
}
+
+ [Fact]
+ public void Linux_NeverReturns_LeadingSlash_When_First_Segment_Sanitizes_To_Empty()
+ {
+ // '\0' replaced with '.' produces "." — SanitizePathSegment converts that to ""
+ // joining ["", "foo"] with '/' would yield "/foo" without a guard
+ var result = FileSafety.SanitizePath("\0/foo", replacement: '.', os: OperatingSystem.Linux);
+
+ Assert.False(result.StartsWith('/') || result.StartsWith('\\'));
+ }
+
+ [Theory]
+ [InlineData("../..")]
+ [InlineData("./.")]
+ public void Linux_Replaces_All_Traversal_Segments(string input)
+ {
+ var result = FileSafety.SanitizePath(input, os: OperatingSystem.Linux);
+
+ Assert.Equal("_/_", result);
+ }
+
+ [Fact]
+ public void Linux_Handles_SoulseekQt_Prefixed_Path()
+ {
+ var result = FileSafety.SanitizePath("@@abcde/foo/bar", os: OperatingSystem.Linux);
+
+ Assert.Equal("@@abcde/foo/bar", result);
+ }
+
+ [Fact]
+ public void Windows_Sanitizes_Colon_In_Drive_Like_Segment()
+ {
+ var result = FileSafety.SanitizePath("C:/Music/song.flac", os: OperatingSystem.Windows);
+
+ Assert.Equal("C_\\Music\\song.flac", result);
+ }
}
} \ No newline at end of file