Skip to content

DYN-5640 AllIndicesOf node breaks as soon as the checked list has any null entry #13773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Libraries/CoreNodes/List.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -1346,7 +1346,7 @@ public static IList AllIndicesOf(IList list, object item)
if (list == null)
return new List<int> { };

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;
}

Expand Down
21 changes: 20 additions & 1 deletion test/Libraries/CoreNodesTests/ListTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -948,6 +948,25 @@ public static void AllIndicesOf()
Assert.IsEmpty(indices);
}

[Test]
[Category("UnitTests")]
public static void AllIndicesOfNullTest()
{
var input = new List<object> { 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()
Expand Down