]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix off-by-one error in LocalizedDatasetPrototype (#28366)
authorTayrtahn <tayrtahn@gmail.com>
Wed, 29 May 2024 03:37:03 +0000 (23:37 -0400)
committerGitHub <noreply@github.com>
Wed, 29 May 2024 03:37:03 +0000 (23:37 -0400)
Content.Shared/Dataset/LocalizedDatasetPrototype.cs
Content.Tests/Shared/LocalizedDatasetPrototypeTest.cs

index 8be9967e309ddac8112d29cf71e9cf0c7fb2583e..2e0aa60c684ac69a82263a0e8bb6071bcae6deeb 100644 (file)
@@ -47,9 +47,9 @@ public sealed partial class LocalizedDatasetValues : IReadOnlyList<string>
     {
         get
         {
-            if (index > Count || index < 0)
+            if (index >= Count || index < 0)
                 throw new IndexOutOfRangeException();
-            return Prefix + index;
+            return Prefix + (index + 1);
         }
     }
 
index 0ec4c076f5b4810dc94fd4826b5559179d2ebbb8..b07b18efa0a99668c94c8277f0961ffafe4530e7 100644 (file)
@@ -46,14 +46,14 @@ public sealed class LocalizedDatasetPrototypeTest : ContentUnitTest
         Assert.That(values, Has.Count.EqualTo(4));
 
         // Make sure indexing works as expected
-        Assert.That(values[0], Is.EqualTo("test-dataset-1"));
-        Assert.That(values[1], Is.EqualTo("test-dataset-2"));
-        Assert.That(values[2], Is.EqualTo("test-dataset-3"));
-        Assert.That(values[3], Is.EqualTo("test-dataset-4"));
-        Assert.Throws<IndexOutOfRangeException>(() => { var x = values[4]; });
-        Assert.Throws<IndexOutOfRangeException>(() => { var x = values[-1]; });
+        Assert.That(testPrototype.Values[0], Is.EqualTo("test-dataset-1"));
+        Assert.That(testPrototype.Values[1], Is.EqualTo("test-dataset-2"));
+        Assert.That(testPrototype.Values[2], Is.EqualTo("test-dataset-3"));
+        Assert.That(testPrototype.Values[3], Is.EqualTo("test-dataset-4"));
+        Assert.Throws<IndexOutOfRangeException>(() => { var x = testPrototype.Values[4]; });
+        Assert.Throws<IndexOutOfRangeException>(() => { var x = testPrototype.Values[-1]; });
 
         // Make sure that the enumerator gets all of the values
-        Assert.That(testPrototype.Values[testPrototype.Values.Count], Is.EqualTo("test-dataset-4"));
+        Assert.That(testPrototype.Values[^1], Is.EqualTo("test-dataset-4"));
     }
 }