diff --git a/src/Libraries/CoreNodes/List.cs b/src/Libraries/CoreNodes/List.cs index 8282185c389..0288c0b7e03 100644 --- a/src/Libraries/CoreNodes/List.cs +++ b/src/Libraries/CoreNodes/List.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -1346,7 +1346,7 @@ public static IList AllIndicesOf(IList list, object item) if (list == null) return new List { }; - var indices = Enumerable.Range(0, list.Count).Where(i => list[i].Equals(item)).ToList(); + var indices = Enumerable.Range(0, list.Count).Where(i => list[i] != null ? list[i].Equals(item) : item == null).ToList(); return indices; } diff --git a/test/Libraries/CoreNodesTests/ListTests.cs b/test/Libraries/CoreNodesTests/ListTests.cs index ce1d17581d9..59e2c24bbf0 100644 --- a/test/Libraries/CoreNodesTests/ListTests.cs +++ b/test/Libraries/CoreNodesTests/ListTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -948,6 +948,25 @@ public static void AllIndicesOf() Assert.IsEmpty(indices); } + [Test] + [Category("UnitTests")] + public static void AllIndicesOfNullTest() + { + var input = new List { true, false, null }; + + var indices = List.AllIndicesOf(input, true); + Assert.True(indices.Count == 1); + Assert.AreEqual(0, indices[0]); + + indices = List.AllIndicesOf(input, false); + Assert.True(indices.Count == 1); + Assert.AreEqual(1, indices[0]); + + indices = List.AllIndicesOf(input, null); + Assert.True(indices.Count == 1); + Assert.AreEqual(2, indices[0]); + } + [Test] [Category("UnitTests")] public static void CleanNullsPreserveIndices()