From: Tayrtahn Date: Wed, 29 May 2024 03:37:03 +0000 (-0400) Subject: Fix off-by-one error in LocalizedDatasetPrototype (#28366) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=7f9ed797afccd2317218f7332250f7bbfa6071a8;p=space-station-14.git Fix off-by-one error in LocalizedDatasetPrototype (#28366) --- diff --git a/Content.Shared/Dataset/LocalizedDatasetPrototype.cs b/Content.Shared/Dataset/LocalizedDatasetPrototype.cs index 8be9967e30..2e0aa60c68 100644 --- a/Content.Shared/Dataset/LocalizedDatasetPrototype.cs +++ b/Content.Shared/Dataset/LocalizedDatasetPrototype.cs @@ -47,9 +47,9 @@ public sealed partial class LocalizedDatasetValues : IReadOnlyList { get { - if (index > Count || index < 0) + if (index >= Count || index < 0) throw new IndexOutOfRangeException(); - return Prefix + index; + return Prefix + (index + 1); } } diff --git a/Content.Tests/Shared/LocalizedDatasetPrototypeTest.cs b/Content.Tests/Shared/LocalizedDatasetPrototypeTest.cs index 0ec4c076f5..b07b18efa0 100644 --- a/Content.Tests/Shared/LocalizedDatasetPrototypeTest.cs +++ b/Content.Tests/Shared/LocalizedDatasetPrototypeTest.cs @@ -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(() => { var x = values[4]; }); - Assert.Throws(() => { 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(() => { var x = testPrototype.Values[4]; }); + Assert.Throws(() => { 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")); } }