Selaa lähdekoodia

Merge pull request #11351 from revam/fix-off-by-one-error-in-get-attribute-value

fix: fix off-by-one error in `GetAttributeValue`
Bond-009 1 vuosi sitten
vanhempi
sitoutus
b4bd3f6151

+ 3 - 2
Emby.Server.Implementations/Library/PathExtensions.cs

@@ -31,8 +31,9 @@ namespace Emby.Server.Implementations.Library
 
 
             var attributeIndex = str.IndexOf(attribute, StringComparison.OrdinalIgnoreCase);
             var attributeIndex = str.IndexOf(attribute, StringComparison.OrdinalIgnoreCase);
 
 
-            // Must be at least 3 characters after the attribute =, ], any character.
-            var maxIndex = str.Length - attribute.Length - 3;
+            // Must be at least 3 characters after the attribute =, ], any character,
+            // then we offset it by 1, because we want the index and not length.
+            var maxIndex = str.Length - attribute.Length - 2;
             while (attributeIndex > -1 && attributeIndex < maxIndex)
             while (attributeIndex > -1 && attributeIndex < maxIndex)
             {
             {
                 var attributeEnd = attributeIndex + attribute.Length;
                 var attributeEnd = attributeIndex + attribute.Length;

+ 6 - 0
tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs

@@ -18,6 +18,12 @@ namespace Jellyfin.Server.Implementations.Tests.Library
         [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]", "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]", "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("[tmdbid=618355]", "tmdbid", "618355")]
         [InlineData("[tmdbid=618355]", "tmdbid", "618355")]
         [InlineData("[tmdbid-618355]", "tmdbid", "618355")]
         [InlineData("[tmdbid-618355]", "tmdbid", "618355")]
         [InlineData("tmdbid=111111][tmdbid=618355]", "tmdbid", "618355")]
         [InlineData("tmdbid=111111][tmdbid=618355]", "tmdbid", "618355")]