aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Server.Implementations.Tests/Library
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Jellyfin.Server.Implementations.Tests/Library')
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Library/DotIgnoreIgnoreRuleTest.cs87
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs19
2 files changed, 84 insertions, 22 deletions
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/DotIgnoreIgnoreRuleTest.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/DotIgnoreIgnoreRuleTest.cs
index d677c9f09..a7bbef7ed 100644
--- a/tests/Jellyfin.Server.Implementations.Tests/Library/DotIgnoreIgnoreRuleTest.cs
+++ b/tests/Jellyfin.Server.Implementations.Tests/Library/DotIgnoreIgnoreRuleTest.cs
@@ -1,30 +1,81 @@
+using Emby.Server.Implementations.Library;
using Xunit;
namespace Jellyfin.Server.Implementations.Tests.Library;
public class DotIgnoreIgnoreRuleTest
{
- [Fact]
- public void Test()
+ private static readonly string[] _rule1 = ["SPs"];
+ private static readonly string[] _rule2 = ["SPs", "!thebestshot.mkv"];
+ private static readonly string[] _rule3 = ["*.txt", @"{\colortbl;\red255\green255\blue255;}", "videos/", @"\invalid\escape\sequence", "*.mkv"];
+ private static readonly string[] _rule4 = [@"{\colortbl;\red255\green255\blue255;}", @"\invalid\escape\sequence"];
+
+ public static TheoryData<string[], string, bool, bool> CheckIgnoreRulesTestData =>
+ new()
+ {
+ // Basic pattern matching
+ { _rule1, "f:/cd/sps/ffffff.mkv", false, true },
+ { _rule1, "cd/sps/ffffff.mkv", false, true },
+ { _rule1, "/cd/sps/ffffff.mkv", false, true },
+
+ // Negate pattern
+ { _rule2, "f:/cd/sps/ffffff.mkv", false, true },
+ { _rule2, "cd/sps/ffffff.mkv", false, true },
+ { _rule2, "/cd/sps/ffffff.mkv", false, true },
+ { _rule2, "f:/cd/sps/thebestshot.mkv", false, false },
+ { _rule2, "cd/sps/thebestshot.mkv", false, false },
+ { _rule2, "/cd/sps/thebestshot.mkv", false, false },
+
+ // Mixed valid and invalid patterns - skips invalid, applies valid
+ { _rule3, "test.txt", false, true },
+ { _rule3, "videos/movie.mp4", false, true },
+ { _rule3, "movie.mkv", false, true },
+ { _rule3, "test.mp3", false, false },
+
+ // Only invalid patterns - falls back to ignore all
+ { _rule4, "any-file.txt", false, true },
+ { _rule4, "any/path/to/file.mkv", false, true },
+ };
+
+ public static TheoryData<string[], string, bool, bool> WindowsPathNormalizationTestData =>
+ new()
+ {
+ // Windows paths with backslashes - should match when normalizePath is true
+ { _rule1, @"C:\cd\sps\ffffff.mkv", false, true },
+ { _rule1, @"D:\media\sps\movie.mkv", false, true },
+ { _rule1, @"\\server\share\sps\file.mkv", false, true },
+
+ // Negate pattern with Windows paths
+ { _rule2, @"C:\cd\sps\ffffff.mkv", false, true },
+ { _rule2, @"C:\cd\sps\thebestshot.mkv", false, false },
+
+ // Directory matching with Windows paths
+ { _rule3, @"C:\videos\movie.mp4", false, true },
+ { _rule3, @"D:\documents\test.txt", false, true },
+ { _rule3, @"E:\music\song.mp3", false, false },
+ };
+
+ [Theory]
+ [MemberData(nameof(CheckIgnoreRulesTestData))]
+ public void CheckIgnoreRules_ReturnsExpectedResult(string[] rules, string path, bool isDirectory, bool expectedIgnored)
+ {
+ Assert.Equal(expectedIgnored, DotIgnoreIgnoreRule.CheckIgnoreRules(path, rules, isDirectory));
+ }
+
+ [Theory]
+ [MemberData(nameof(WindowsPathNormalizationTestData))]
+ public void CheckIgnoreRules_WithWindowsPaths_NormalizesBackslashes(string[] rules, string path, bool isDirectory, bool expectedIgnored)
{
- var ignore = new Ignore.Ignore();
- ignore.Add("SPs");
- Assert.True(ignore.IsIgnored("f:/cd/sps/ffffff.mkv"));
- Assert.True(ignore.IsIgnored("cd/sps/ffffff.mkv"));
- Assert.True(ignore.IsIgnored("/cd/sps/ffffff.mkv"));
+ // With normalizePath=true, backslashes should be converted to forward slashes
+ Assert.Equal(expectedIgnored, DotIgnoreIgnoreRule.CheckIgnoreRules(path, rules, isDirectory, normalizePath: true));
}
- [Fact]
- public void TestNegatePattern()
+ [Theory]
+ [InlineData(@"C:\cd\sps\ffffff.mkv")]
+ [InlineData(@"D:\media\sps\movie.mkv")]
+ public void CheckIgnoreRules_WithWindowsPaths_WithoutNormalization_DoesNotMatch(string path)
{
- var ignore = new Ignore.Ignore();
- ignore.Add("SPs");
- ignore.Add("!thebestshot.mkv");
- Assert.True(ignore.IsIgnored("f:/cd/sps/ffffff.mkv"));
- Assert.True(ignore.IsIgnored("cd/sps/ffffff.mkv"));
- Assert.True(ignore.IsIgnored("/cd/sps/ffffff.mkv"));
- Assert.True(!ignore.IsIgnored("f:/cd/sps/thebestshot.mkv"));
- Assert.True(!ignore.IsIgnored("cd/sps/thebestshot.mkv"));
- Assert.True(!ignore.IsIgnored("/cd/sps/thebestshot.mkv"));
+ // Without normalization, Windows paths with backslashes won't match patterns expecting forward slashes
+ Assert.False(DotIgnoreIgnoreRule.CheckIgnoreRules(path, _rule1, isDirectory: false, normalizePath: false));
}
}
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs
index 940e3c2b1..650d67b19 100644
--- a/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs
+++ b/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs
@@ -11,21 +11,29 @@ namespace Jellyfin.Server.Implementations.Tests.Library
[InlineData("Superman: Red Son [imdbid=tt10985510]", "imdbid", "tt10985510")]
[InlineData("Superman: Red Son [imdbid-tt10985510]", "imdbid", "tt10985510")]
[InlineData("Superman: Red Son - tt10985510", "imdbid", "tt10985510")]
+ [InlineData("Superman: Red Son {imdbid=tt10985510}", "imdbid", "tt10985510")]
+ [InlineData("Superman: Red Son (imdbid-tt10985510)", "imdbid", "tt10985510")]
[InlineData("Superman: Red Son", "imdbid", null)]
- [InlineData("Superman: Red Son", "something", null)]
[InlineData("Superman: Red Son [imdbid1=tt11111111][imdbid=tt10985510]", "imdbid", "tt10985510")]
- [InlineData("Superman: Red Son [imdbid1-tt11111111][imdbid=tt10985510]", "imdbid", "tt10985510")]
+ [InlineData("Superman: Red Son {imdbid1=tt11111111}(imdbid=tt10985510)", "imdbid", "tt10985510")]
+ [InlineData("Superman: Red Son (imdbid1-tt11111111)[imdbid=tt10985510]", "imdbid", "tt10985510")]
[InlineData("Superman: Red Son [tmdbid=618355][imdbid=tt10985510]", "imdbid", "tt10985510")]
- [InlineData("Superman: Red Son [tmdbid-618355][imdbid-tt10985510]", "imdbid", "tt10985510")]
- [InlineData("Superman: Red Son [tmdbid-618355][imdbid-tt10985510]", "tmdbid", "618355")]
+ [InlineData("Superman: Red Son [tmdbid-618355]{imdbid-tt10985510}", "imdbid", "tt10985510")]
+ [InlineData("Superman: Red Son (tmdbid-618355)[imdbid-tt10985510]", "tmdbid", "618355")]
[InlineData("Superman: Red Son [providera-id=1]", "providera-id", "1")]
[InlineData("Superman: Red Son [providerb-id=2]", "providerb-id", "2")]
[InlineData("Superman: Red Son [providera id=4]", "providera id", "4")]
[InlineData("Superman: Red Son [providerb id=5]", "providerb id", "5")]
[InlineData("Superman: Red Son [tmdbid=3]", "tmdbid", "3")]
[InlineData("Superman: Red Son [tvdbid-6]", "tvdbid", "6")]
+ [InlineData("Superman: Red Son {tmdbid=3}", "tmdbid", "3")]
+ [InlineData("Superman: Red Son (tvdbid-6)", "tvdbid", "6")]
[InlineData("[tmdbid=618355]", "tmdbid", "618355")]
+ [InlineData("{tmdbid=618355}", "tmdbid", "618355")]
+ [InlineData("(tmdbid=618355)", "tmdbid", "618355")]
[InlineData("[tmdbid-618355]", "tmdbid", "618355")]
+ [InlineData("{tmdbid-618355)", "tmdbid", null)]
+ [InlineData("[tmdbid-618355}", "tmdbid", null)]
[InlineData("tmdbid=111111][tmdbid=618355]", "tmdbid", "618355")]
[InlineData("[tmdbid=618355]tmdbid=111111]", "tmdbid", "618355")]
[InlineData("tmdbid=618355]", "tmdbid", null)]
@@ -36,6 +44,9 @@ namespace Jellyfin.Server.Implementations.Tests.Library
[InlineData("[tmdbid=][imdbid=tt10985510]", "tmdbid", null)]
[InlineData("[tmdbid-][imdbid-tt10985510]", "tmdbid", null)]
[InlineData("Superman: Red Son [tmdbid-618355][tmdbid=1234567]", "tmdbid", "618355")]
+ [InlineData("{tmdbid=}{imdbid=tt10985510}", "tmdbid", null)]
+ [InlineData("(tmdbid-)(imdbid-tt10985510)", "tmdbid", null)]
+ [InlineData("Superman: Red Son {tmdbid-618355}{tmdbid=1234567}", "tmdbid", "618355")]
public void GetAttributeValue_ValidArgs_Correct(string input, string attribute, string? expectedResult)
{
Assert.Equal(expectedResult, PathExtensions.GetAttributeValue(input, attribute));